B
Blaine
Hello,
I have a class that implements Runnable and it's constructor sets of
some vars to be global. However when I run the code (using the
..start()) the global vars are not availiable.
The following code creates the output:
Start
When you would expect it to create
Start RUNNING
How can I get this expected output?
Squirrel squirrel = new Squirrel(in,out );
Thread squirrelThread = new Thread ( squirrel );
squirrelThread.start();
public class Squirrel implements Runnable {
private InputStream inRS232;
private OutputStream outRS232;
/** Creates a new instance of Squirrel */
public Squirrel(InputStream inStream, OutputStream outStream) {
this.setInputStream(inStream);
this.setOutputStream(outStream);
this.writeRS232("\r\nStart");
}
public void run(){
this.setRunning(true)
this.writeRS232(" RUNNING ");
}
public void setInputStream(InputStream in){
this.inRS232 = in;
}
public void setOutputStream(OutputStream out){
this.outRS232 = out;
}
private void writeRS232(String request){
try {
this.outRS232.write( request.getBytes() );
} catch (IOException e) {
System.out.println( e.getMessage() );
}
}
}
I have a class that implements Runnable and it's constructor sets of
some vars to be global. However when I run the code (using the
..start()) the global vars are not availiable.
The following code creates the output:
Start
When you would expect it to create
Start RUNNING
How can I get this expected output?
Squirrel squirrel = new Squirrel(in,out );
Thread squirrelThread = new Thread ( squirrel );
squirrelThread.start();
public class Squirrel implements Runnable {
private InputStream inRS232;
private OutputStream outRS232;
/** Creates a new instance of Squirrel */
public Squirrel(InputStream inStream, OutputStream outStream) {
this.setInputStream(inStream);
this.setOutputStream(outStream);
this.writeRS232("\r\nStart");
}
public void run(){
this.setRunning(true)
this.writeRS232(" RUNNING ");
}
public void setInputStream(InputStream in){
this.inRS232 = in;
}
public void setOutputStream(OutputStream out){
this.outRS232 = out;
}
private void writeRS232(String request){
try {
this.outRS232.write( request.getBytes() );
} catch (IOException e) {
System.out.println( e.getMessage() );
}
}
}