wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes what diffrent way of creating thread? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "what diffrent way of creating thread?" Watch "what diffrent way of creating thread?" New topic
Author

what diffrent way of creating thread?

balu venkat
Greenhorn

Joined: Nov 23, 2005
Posts: 2
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
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
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.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what diffrent way of creating thread?
 
Similar Threads
Inner Class basic dought
dought!!
dan exam dought 5
Shift Operator Dought
dought