| Author |
SCJP / strange behaviour when using Thread-Constructor
|
Guido Ranft
Greenhorn
Joined: Mar 08, 2012
Posts: 1
|
|
I thought when I create an extended thread instance with a constructor object implementing runnable
the run-method of the constructor instance is used. Instead the overriden method is used. Why?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19230
|
|
Welcome to the Ranch! Could you please UseCodeTags next time?
Anyway, when a Thread is started, its run() method is executed in a new thread. The default behaviour is to call the run() method of its Runnable. Since you've overridden the method you don't get that behaviour anymore. A simple fix is to call super.run() inside your run() method.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Istvan Kovacs
Ranch Hand
Joined: May 06, 2010
Posts: 100
|
|
|
You are asking the wrong question. The question you should be asking is "Why does Thread run the supplied Runnable?". (Tip: read its source code.) Once you figure that out, you'll know the answer to your question.
|
 |
 |
|
|
subject: SCJP / strange behaviour when using Thread-Constructor
|
|
|