This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to run another programme using threads  RSS feed

 
ravi kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to run another java class file by using threads for every 10 minutes.For that I wrote a code like the Below.but I able to run that programme for only one time.How can I run that class for every 10 mins.
public static void main(String args[])throws Exception{
Thread t=new Thread();
Process p = Runtime.getRuntime().exec(new String("java Hello"));
InputStream pin = p.getInputStream();//stdout of created process
OutputStream pou = p.getOutputStream();//stdin of process
InputStream pes = p.getErrorStream();//stderr of process
while(true){
try{
p.exitValue(); //throes exception if process is running
break;
}catch(IllegalThreadStateException its){
byte b[] = new byte[1000];
int nob;
nob = pin.read(b,0,1000);
t.start();
for(int i =0;i<nob;i++)
System.out.print((char)b[i]);
t.sleep(1000);}}}
Please Help Me in This Regard.THANKS IN ADVANCE..
-RAVI KUMAR
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's try a very small part of the problem first. See what this does for you:

You found the Thread.sleep() method before, but this shows you can use it with much less effort.

Now keep this loop and replace the print line with a call to a method to run your other program. Show us how that looks, and we'll dig into the runtime exec next!

BTW: Use the CODE button below the ranch editor to preserve the indentation in your code samples.
[ April 28, 2006: Message edited by: Stan James ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!