• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Doubt in threads !!

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic