Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not getting the output of run method?

 
upanshu vaid
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


getting out put as
main thread started
then wait for 1sec and then
main thread started1.
Thanks
 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no instance of T1 created and calling the run() method.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raymond Tong wrote:There is no instance of T1 created and calling the run() method.

Correct. Besides, your class T1(why classname is T1? ) is not a thread or a Runnable.

What you are doing is:
Start a 'blank' thread - which actually does nothing:

Above code will call default run method of Thread class.

What you need to do is:
1) Create a class that extends Thread or implements Runnable
2) Override run method
3) Create a thread which accepts object of your thread/runnable implementation
4) Start the thread

I hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic