Lee Mark wrote:but what if i create i new for every thread befor thay start i am getting same output i tried it running atleast 15 itimes to ensure tht..
i am adding
mr.i = new Integer(2);
before each thread start call..
If I understood you correctly, you've suggested following:
You have to understand that threads are not really executed in parallel, however in a sequence (handled by OS).
When you call start() on a thread, this just means that the thread is ready to run, however whether it will be started or not is up to the scheduler.
So, the scheduler determines which thread will be started at what time...
Therefore the result could/would be the same as without above changes, because all running threads will have to gain the lock on e.g. Integer(3).