Scripting with beanshell - making a thread solution...

Ok here is the problem i have and are looking for ideas how to solve it. We have a single threadded server that are using beanshell scripts.

Now... inside the scripts we want to be able to sleep (wait).

For example:

void run(){

print("test");

wait(5);// wait 5 seconds

print("test2");

}

So what i would basically want is that the script is put into somekind of queue, where it will reside for 5 seconds. And then the server would step through the queue and if 5 seconds has passed it would continue executing...

Is there any "easy" solution to fix this?

[781 byte] By [aeona] at [2007-10-3 4:34:24]
# 1
Can I guess you want to do this because you don't want the excuting thread to pause?Why don't you just spawn a new thread to execute the script? Then it won't block normal execution but can pause as it likes.
cotton.ma at 2007-7-14 22:38:03 > top of Java-index,Java Essentials,Java Programming...
# 2
Since the script may not concurrently modify anything else in the server. It is a single threadded server (most of it).
aeona at 2007-7-14 22:38:03 > top of Java-index,Java Essentials,Java Programming...
# 3

The only solution i come up with so far is making the script call a "script manager" to do the waiting, and with that add a "callback" method.

So the script would be like

run(){

print("test");

manager.wait(2, "step2()");

}

step2(){

print("test2");

}

The manager would take care of making sure that the callback method is called at the correct time.

aeona at 2007-7-14 22:38:03 > top of Java-index,Java Essentials,Java Programming...