I have a scenario like.... There are four threads named as Thread1, Thread2, Thread3 and Thread4. and there is one counter variable. And I want output as below
Thread1 : value of counter variable is = 0
Thread2 : value of counter variable is = 1
Thread3 : value of counter variable is = 2
Thread4 : value of counter variable is = 3
Thread1 : value of counter variable is = 4
Thread2 : value of counter variable is = 5
Thread3 : value of counter variable is = 6
Thread4 : value of counter variable is = 7
Thread1 : value of counter variable is = 8
Thread2 : value of counter variable is = 9
Thread3 : value of counter variable is = 10
Thread4 : value of counter variable is = 11
Even I have done this by logically. But I want something like, When Thread1 is printing the variable of counter then all the remaining threads should wait.....then after Thread2 should come to the picture and print the counter variable and rest should wait.
Suggest me the best solution for this. Thanks in advance :-)