• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to run another programme using threads

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic