File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "what diffrent way of creating thread?" Watch "what diffrent way of creating thread?" New topic

what diffrent way of creating thread?

balu venkat

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..

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...

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:
subject: what diffrent way of creating thread?
It's not a secret anymore!