• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

threads

 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am playing around with Threads.
I understand that, we can create threads by two methods
1. by Extending Thread class
2. Implementing Runnable.
But, I just want to know, when to which method? I tried to find out in some books, I am referring and JLS also... But, Could not get any clear idea about about choosing the right method..
Can anyone plz exaplain...
thanks
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is easier extending Thread than implementing Runnable and then creating a new Thread. Thus use the first method whenever possible. That is whenever your class is already extending of another you can't go for the first method.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Murthy,
There is only one way to create thread. That is
by creating a Thread object ( or its subclass ).
Even if you use a Runnable object you still need
a Thread object. In this case you delegate what
should done in Thread's run() method to the run()
method of that Runnable object. This achieves some flexibility ( A thread's executing code doesn't have to be inside a Thread's object but can be anywhere else! )
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What other people think.
[ July 01, 2002: Message edited by: Anthony Villanueva ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic