Which is better in terms of performance Thread class or Runnable interface and why?
Please help Thanks in advance
Jitendra
SCJP1.5
SCWCD1.5
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
I'm sure there's not enough performance difference to worry about, or probably even measure. We generally prefer to implement Runnable because extending a concrete class like Thread has a lot of risks and because our own classes are not really special types of Thread but tasks that can be run on a thread.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I'm sure there's not enough performance difference to worry about, or probably even measure.
I agree. I also don't see any reason as to why one would be better, in terms of performance. But, I guess there is no harm to actually try it out.
Two cases... 100,000 instances of a class that inherits from the Thread class, with a run() method that does nothing... vs... 100,000 instances of a class that implements Runnable, passed to a Thread object, with a run() method that does nothing... in a loop, call start(), then join().
Total time around 17 to 18 seconds. On some runs, the first case is faster, on others, the second case is faster.
hi friends, I'm ok with whatever you said about the implementation part , But can anybody tell me why we need Thread Class when we already have Runnable interface..
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
posted
0
Originally posted by deepak munjlani: hi friends, I'm ok with whatever you said about the implementation part , But can anybody tell me why we need Thread Class when we already have Runnable interface..
You already asked this in another post. Please don't cross-post the same question.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P