| Author |
Lock Mechanism Doubt
|
Lee Mark
Ranch Hand
Joined: Mar 05, 2009
Posts: 46
|
|
please explain the behaviour of this code..
|
 |
Rok Štelcer
Ranch Hand
Joined: Nov 03, 2009
Posts: 101
|
|
Hi,
I'm not sure what do you want from us to explain, so I've added a few comments.
Lee Mark wrote:please explain the behaviour of this code.
Hope this helps.
Regards,
Rok
|
SCJP, SCWCD
|
 |
Lee Mark
Ranch Hand
Joined: Mar 05, 2009
Posts: 46
|
|
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..
comment again
|
 |
Rok Štelcer
Ranch Hand
Joined: Nov 03, 2009
Posts: 101
|
|
Hi,
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..
comment again
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).
Hope I answered your question.
Regards,
Rok
|
 |
 |
|
|
subject: Lock Mechanism Doubt
|
|
|