• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Doubt in threads !!

 
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!!!
 
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??
 
Wanderer
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.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic