Forums Register Login

Lock Mechanism Doubt

+Pie Number of slices to send: Send



please explain the behaviour of this code..

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1362 times.
Similar Threads
Please explain this code
Synchronized Block Of Code
join() method in Thread doesn't work as expected
How to make one thread die before another thread
Thread Behaviour? Help!!!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:16:24.