Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Lock Mechanism Doubt

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



please explain the behaviour of this code..

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Lee Mark
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic