aspose file tools*
The moose likes Groovy and the fly likes GroovyShell wait? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "GroovyShell wait?" Watch "GroovyShell wait?" New topic
Author

GroovyShell wait?

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi-

I am running a Groovy script which picks up a list of scripts and runs them (via GroovyShell).
How can I block execution so that script 1 executes, then script 2 etc.

Or is this not possible?
thanks
max
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Assuming your scripts are not multi-threaded, this shouldn't be an issue and the scripts should run on the GroovyShell instance sequentially. Has this not been the case?


A good workman is known by his tools.
Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi Marc-

No. My main script reads a list of scripts from a table and loops through and fires off a script for each one (using the GroovyShell.run command). The 1st script is still running when the next one is picked up. But now that you mention it, the first script does run a Thread.

I think I need something similar to the cmd.execute() where I can issue a process.waitFor()

I'm trying to fire off the groovy command using this syntax but so far have not had much luck.

Max
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

If eliminating the spun-off thread is a possibility (and just run all processing in the main thread), that could be the quickest fix.

Another trick would be to end the code of the 1st script with a while loop that continues until some condition gets set (a condition/flag that gets set by the spun-off Thread upon its completion).

Basically you need to ensure that the extra Thread finishes before the 1st script returns.
Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi Marc-

What I opted for - since this is a generic scriptrunner script and could include Threads - is to use the cmd.execute approach with a process.waitFor.
I managed to get it to work.

thanks
Max
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GroovyShell wait?