Popular Posts

Showing posts with label thread. Show all posts
Showing posts with label thread. Show all posts

Saturday, July 16, 2011

JAVA - synchronized

synchronized methods acquire lock on objects.


Here "my" and "yours" are two different instances, so "my" threads willl acquire lock on "my" instance and "yours" threads will acquire lock on "yours" instance.

Example is shown below:

JAVA - join() Method

When non-static join() method is invoked it will make currently running thread to wait until the invoking thread finished its execution.


 
Here th[i].join() will make main thread to wait until it is finished. So,
 
main--->
             th[0].join()---> 
                                  main-->
                                             th[1].join()---> 
                                                                  main-->
                                                                             th[2].join()--->   
                                                                                                   main---->
 
Thus join() method makes to Join the current thread after 
it goes to dead state.