• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What does new Thread() mean?

 
Ranch Hand
Posts: 45
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What does

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

mean?
Which thread instance will be started ?



 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 258
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic