• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does new Thread() mean?

 
Senthil Kumar Sekar
Ranch Hand
Posts: 45
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What does

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

mean?
Which thread instance will be started ?



 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raymond Tong wrote:
You can check the source code of "Thread" class to know more about the details.


Better to just read the documentation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic