Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

what diffrent way of creating thread?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,

i have one dought ..
clearly .. two way of i can create thread
1) Extending Thread class
and 2) by Implementing of Runnable interface..

but
my dought is...

if u r directly creating Thread class object what it happends..
is this another process creating thread...

and what is use of these 3 diffrent ways..?

please help me...

Thanks
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on your appl's class hierarchy. If your class can subclass the Thread class and override run(), you may choose to use the fact that the Thread class implements Runnable. Otherwise, use 2 separate objects for Thread and Runnable.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There has been extensive discussion in other threads about the difference between extending Thread and implementing Runnable. Search the forums for that.

One extra point. It seems that there is often confusion between instances of the Java class java.lang.Thread, active Java threads and operating system threads.

The class java.lang.Thread is a Java class than you can instantiate, but just instantiating it does not start a new active Java thread. Only when you call start() does a new Java thread become active. Also, after the Java thread has finished running, the instance of java.lang.Thread remains accessible, until all references to it have gone away.

There is an instance of java.lang.Thread for every active Java thread, but there is not necessarily an active Java thread for ever instance of java.lang.Thread.

While modern JVMs often do have one operating system thread per active Java thread, there is no necessity for this to be true. The JVM is free to implement java.lang.Thread any way it likes, providing that the implementation adheres to the specification. And the specification deliberately allows quite a lot of lattitude.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic