File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GroovyShell wait?

 
Max Tomlinson
Ranch Hand
Posts: 365
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Max Tomlinson
Ranch Hand
Posts: 365
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 365
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic