aspose file tools*
The moose likes Threads and Synchronization and the fly likes SCJP / strange behaviour when using Thread-Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "SCJP / strange behaviour when using Thread-Constructor" Watch "SCJP / strange behaviour when using Thread-Constructor" New topic
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: 19784
    
  20

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 - OCEEJBD 6
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SCJP / strange behaviour when using Thread-Constructor