Dear All
I have written a simple program using thread. My aim is to run a command. Please lead me how to do ? I am just posting my start code here.
[code=java]
package com.pjerald.rob ot;
import java.net.*;
import java.io.*;
public class RunCmd extends Thread
{
public static void main(String[] args)
{
//RunCmd rc = new RunCmd("ls -ltr");
RunCmd rc = new RunCmd("mkdir -p test1/test2/test3");
rc.start();
}
String cmd = null;
RunCmd(String cmd) {
this.cmd = cmd;
}
public void run() {
if(cmd != null)
{
try{
Thread t = new Thread(cmd);
t.start();
int count = 0;
do
{
if(count == 100)
{
System.out.prin tln(" TIME OUT for Thread ::"+t.getName() );
t.destroy();
}
t.sleep(500);
System.out.prin tln("Thread ::"+t.getName() +" running");
count = count+1;
}
while(t.isAlive ());
}
catch(Exception e)
{
e.printStackTra ce();
}
}
}
}
[/code]
I have written a simple program using thread. My aim is to run a command. Please lead me how to do ? I am just posting my start code here.
[code=java]
package com.pjerald.rob ot;
import java.net.*;
import java.io.*;
public class RunCmd extends Thread
{
public static void main(String[] args)
{
//RunCmd rc = new RunCmd("ls -ltr");
RunCmd rc = new RunCmd("mkdir -p test1/test2/test3");
rc.start();
}
String cmd = null;
RunCmd(String cmd) {
this.cmd = cmd;
}
public void run() {
if(cmd != null)
{
try{
Thread t = new Thread(cmd);
t.start();
int count = 0;
do
{
if(count == 100)
{
System.out.prin tln(" TIME OUT for Thread ::"+t.getName() );
t.destroy();
}
t.sleep(500);
System.out.prin tln("Thread ::"+t.getName() +" running");
count = count+1;
}
while(t.isAlive ());
}
catch(Exception e)
{
e.printStackTra ce();
}
}
}
}
[/code]
Comment