aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Related Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Related Problem" Watch "Thread Related Problem" New topic
Author

Thread Related Problem

Rushikesh Wagh
Ranch Hand

Joined: Jun 18, 2005
Posts: 58
Dear Friends,

Last Few Days I am facing a small problem. Its related to threads.
I am creating a thread, in its run() method i am calling a batch file by using the following command,

Process p = Runtime.getRuntime().exec("MySample1.bat");

Now, the problem is, i want to run few more batches(say MySample2.bat, MySample3.bat..) in loop. Before that i want to make sure that the batches run one afer another....

Any kind of suggessions are welcome...


Best Regards,
Rushikesh Wagh
SCJP 1.4 (2005)
SCJP 1.6 (2010)
sherin stephen
Greenhorn

Joined: May 14, 2006
Posts: 6

i dont think of that is possible straight away because you are invoking a batch process that is beyond the controll of your program
Nilesh Deshpande
Ranch Hand

Joined: Jan 11, 2006
Posts: 36
Create a batch file which will contain the calls to other batch files.
And call that batch file from the java program.

Dont use the the start statement in batch file. By default the batch calls are single threaded. So no over lap will happen.

You should also do the error handling in the batch scripts.
Terry Huang
Greenhorn

Joined: May 16, 2006
Posts: 25
um im not quite sure that i fully understand you but what you can do is do something like this
Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
Hi,
You can use this command
p.waitFor();
"causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits."

Put this at the start (or end) of the for loop to make it wait for the batch process to finish before kicking off the next one.

/Tom


<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread Related Problem