File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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

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

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
You can use this command
"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.


<a href="" target="_blank" rel="nofollow">Use Code Tags!!</a>
I agree. Here's the link:
subject: Thread Related Problem
It's not a secret anymore!