Java: changing variable of calling thread
I have the following code:
public class Shell {
String status;
public void runCmd(final String cmd,String status) throws Exception{
this.status = status;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
process = rtime.exec(cmd);
process.waitFor();
this.status = "check out done";
} catch (IOException e) {
} catch (InterruptedException e) {
}
}
});
t.start();
}
}
but java doesn't let me change the status variable inside the new thread
t.May be I need some sort of inter thread communication.I am new to
threads,please tell me how to do this.
No comments:
Post a Comment