its a server side Javascript (rhino engine), so setTimeout is not available. how to run a function asynchronously?
Have a look at the Multithreaded Script Execution example on the Rhino Examples page. Basically, JavaScript does not support threading directly, but you may be able to use a Java thread to achieve what you are looking for.
Multithreaded Script Execution