• 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

synchronrized and join()

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class test
{
synchronized method1()
{
// some code...
}
}
class demo extends Thread
{
test t;
demo(test t1)
{
t = t1;
}
public void run()
{
t.method1();
}
}
class sample
{
public static void main()
{
test tx = new test()
demo d = new demo(tx);
d.start();
//What will happen if d.join(); is executed
}
}
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The current thread (the one running the main method) will wait for the execution of t.method1() to finish in the thread labeled d and then continue with execution of the main. Since there is no more code in the main the application will return/end.
Is that the kind of answer you were looking for here?
Paul
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
if you want to find what join() does, see this code:

here if you comment the t.join(); , then even before the run method completes, the "exiting main" will be printed, i.e the main thread will exit before the thread t completes. But if you run the code as it is, then the main thread will wait for the thread t to complete. Then after "printing 999" is printed, "exiting main" will be printed.
I hope this is what u wanted
bye
Tanveer
Tanveer I have modified your code so that it has a try block for the join() method . Hope you don't mind

[This message has been edited by Rahul Mahindrakar (edited December 12, 2000).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic