aspose file tools*
The moose likes Threads and Synchronization and the fly likes What does new Thread() mean? 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 does new Thread() mean?" Watch "What does new Thread() mean?" New topic
Author

What does new Thread() mean?

Senthil Kumar Sekar
Ranch Hand

Joined: Aug 08, 2010
Posts: 45


What does

Thread thread = new Thread();
thread.start);

mean?
Which thread instance will be started ?



Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1505
    
    5

Hi Senthil Kumar Sekar,

will give you a compile time error. It should be

The code creates a new object of Thread class and starts the thread.
Senthil Kumar Sekar wrote:Which thread instance will be started ?

A new thread instance will be started. I didn't get this question clearly.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Senthil Kumar Sekar wrote:
What does

Thread thread = new Thread();
thread.start);

mean?
Which thread instance will be started ?


The one pointed to by the thread variable, which is the one you just created.
Senthil Kumar Sekar
Ranch Hand

Joined: Aug 08, 2010
Posts: 45


Actually iam not passing any Runnable object.I am just creating it by

Thread thread = new java.lang.Thread();
thread.start();

iam not creating the object for subclass of Java.lang.Thread.


What does this indicate?

Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

Senthil Kumar Sekar wrote:
Actually iam not passing any Runnable object.I am just creating it by

Thread thread = new java.lang.Thread();
thread.start();

iam not creating the object for subclass of Java.lang.Thread.


What does this indicate?


thread.run() will eventually be called
Because you have neither extends Thread to override the run method nor passing any Runnable object, it won't do anything and return.

You can check the source code of "Thread" class to know more about the details.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Senthil Kumar Sekar wrote:
Actually iam not passing any Runnable object.I am just creating it by

Thread thread = new java.lang.Thread();
thread.start();

iam not creating the object for subclass of Java.lang.Thread.


What does this indicate?



Try reading the docs. That's always your first place to start.
http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html#start()
http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html#run()
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Raymond Tong wrote:
You can check the source code of "Thread" class to know more about the details.


Better to just read the documentation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What does new Thread() mean?