• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread Locks

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1) If an object can have only one lock, then how come a single thread can obtain multiple locks on one object?
Q2) "Daemon Threads die when all the user threads die." Is it true? I thought Daemon threads are independent of life time of user threads.
[This message has been edited by Rana Thakur (edited March 10, 2001).]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An object has one lock.
Exactly how the lock mechanism keeps track of the number of times a specific Thread has entered synchronized code in a particular object is up to the implementor of the JVM. This is one of the areas that JVM makers concentrate on for speedups.
The Deamon Threads that happen to be running when the last user Thread dies are automatically killed so the program can exit.
Bill

------------------
author of:
 
Rana Thakur
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,
Thanks a lot....
As you said
--------------
Exactly how the lock mechanism keeps track of the number of times a specific Thread has entered synchronized code in a particular object is up to the implementor of the JVM.
--------------------------
Once a Thread acquires lock for object it can enter any of its synchronized code any number of times without the need for re-acquiring the lock. So it seems to me that a Thread can at most acquire one lock on any object.
What happens if the synchronized code is re-entrant? Does the Thread needs to re-acquire the lock each time it invokes the code. I think no. or am I wrong?

----------------------
The Deamon Threads that happen to be running when the last user Thread dies are automatically killed so the program can exit.
------------------------
So the statement
"JVM exits when there are no user threads running" and
"JVM exits when there are no threads running" are same?
because Daemon threads are anyway killed as the last user thread dies.

[This message has been edited by Rana Thakur (edited March 10, 2001).]
[This message has been edited by Rana Thakur (edited March 10, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic