Hi, In multithread application more than one
thread can concurrently access and modify shared variable which may result in data race problems. Okey, lets do it practically
When i ran A1, i got data race problem and got output like
1 3 4 2 5 7 8 6 9 = First Run
1 3 2 4 5 6 7 8 9 = Second Run
so i add 'synchronized' keyword to the increment method in //Thread Implemention A and problem is fixed and now output is
1 2 3 4 5 6 7 8 9 (for multiple runs)
In case of A2 and A3 i ran the default implementation (without adding 'synchronized' keyword to increment method) and got the data race problem. i changed it and added ('synchronized)' keyword to increment method in
//Thread Implemention A and //Thread Implemention B but i still got the data race problem
2) What is the difference between A1 and A2 , does they both result in creating three threads ? I tried and from the output (by running A2 and A3) what i understood is that they both are not same ..!!