• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in threads !!

 
Ganesh Kumar
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
In the below code i can understand that their are two threads running one is main and the another one is the user created.The user created will go to run method once if start is given to it and will die once it leaves the run method.Then how can "tt.loop" will be executed???

In the output it shows that it will be executed by main.How can main will execute it when that method is called by the user created thread reference??









Please help me!!!
 
Biswajit Paria
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println("about to leave loop() - " + name);} public static void main(String[] args) { TwoThread tt = new TwoThread(); tt.setName("my worker thread"); tt.start(); try { System.out.println("another thread calling......"); Thread.sleep(700); } catch ( InterruptedException x ) { } Thread t = Thread.currentThread(); String name = t.getName(); System.out.println("Test name="+ name); tt.loop(); }}

Here tt.start() will create a new Thread and will execute loop() separately.

While Simply calling tt.loop() will be excecuted in main Thread.
[ July 17, 2007: Message edited by: Jim Yingst ]
 
Ganesh Kumar
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya i can get it but will that main do it by taking tt reference??
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Biswajit, I took the unusual step of removing the [ code ] tags from your post, because you didn't have any newlines in there. It was just one huge line of code that was forcing the rest of the page to be far too wide. If you want, you can re-edit it to include both [ code ] tags and newlines.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!