Thread: Introduction
View Single Post
  #4 (permalink)  
Old 05-31-2007, 10:20 PM
levent levent is offline
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Quote:
I do in fact write the data to the thread's constructor but to get it into the run method (which takes no parameters) of the thread I need to store the data in class level variables to make it available.
But once you send it to the constructor, you should save the data inside local variables. And after calling start, your thread will be able to reach them via local variables. Am i missing something?

The code will be sth like this:

Code:
class MyThread extends Thread { private String myData1; private int myData2; public MyThread(String myData1, int myData2) { this.myData1 = myData1; this.myData2 = myData2; } public void run() { // Use your local variables here now System.out.println(myData1); } }
Reply With Quote