Home Tutorialhelp Allcomments Java Thread Synchronizedthreads

 
 

Comments

 
User Comments for the tutorial:

Synchronized Threads



Total comments: 6      View Tutorial    Discuss: Synchronized Threads
Advertisement
Comments

what about a Thread.sleep inside Share?
If the share method has a thread.sleep call in it, then the messages overlap: public class Share extends Thread{ static String msg[]={"This", "is", "a", "synchronized", "variable"}; Share(String threadname){ super(threadname); }  

synchronization in distributed environment
I have a scenario to implement. we have a clustered environment and we need to synchronize a method acess in business layer of our application. Now in my opinion we will be having two different JVM and two different instance of application running o 

My Comments
The actual example should be, Here myVar is the lock used by both threads public class SynThread1 { public static void main(String[] args) { String myVar = "abc"; Share t1=new Share(myVar); t1.start(); Share t2=new Share(m 

The above examples aren't properly synchronized
Please consider the fact that the above to examples does not show proper synchronization due to the fact that there are two share objects and hence there are two share Object locks. So thread one and thread two can mix up together. A way to avoid  

In these examples the Code is NOT synchronized
Please consider the fact that the above to examples does not show proper synchronization due to the fact that there are two share objects and hence there are two share Object locks. So thread one and thread two can mix up together. A way to avoid  

Not correctly synchronized
In this example, programmer is actually creating two different instances of Share class !!...Although we get the output most of the time as given here,code is not properly synchronized.He should have written synchronized(Share.class) instead of synch 

Related Tutorial and Articles
Advertisements Advertisements
 

 

 

DMCA.com