passing parameters to run() method of a thread?
hello ppl
is it possible to pass any parameters to the run() method of a thread
moreover if i create a thread foo the only method that can run is run() ? i know that i can have more methods and just call them via run().
i mean that if i create the constructor of the foo class then first the constructor will be called and then the run() method.but in this way only the code inside run() will run autonomously(meaning that for example i'll be able to press a button of my gui).
thx in advance. =)
[535 byte] By [
tasoss] at [2007-9-26 1:25:50]

not sure I understand the question completely, but you can try the following. Set up whatever arameters your requiring as member variables of your Runnable. Overload the run() method with parameter list you need. In this overloaded method initialize the member variables in your runnable, which can be used in the run() , no arg version,/ Then the last line of the overloaded version call run(), again no-arg version.
Not really familiar with thread programming, but I dont see why this wont work.
Hopefully I understood the question correctly, and this is of some help...
You can not pass parameter to run method of a thread. The signature of run method must be the same as defined in Runnable interface. That is "public void run()".
In any case you never start a thread by calling its run() method. You start the thread by calling Thread.start() method.
If you need to pass data to the thread you may pass data during the initialization (using constructor) or you may call another method on the thread object before calling the Thread.start() method.