Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Related Problem

 
Rushikesh Wagh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
sherin stephen
Greenhorn
Posts: 6
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
um im not quite sure that i fully understand you but what you can do is do something like this
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic