• 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's Locks

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would this be intersting ?!!
Any ideas ?


14.18 The synchronized Statement
......
A single thread may hold a lock more than once.
The example:

class Test {
public static void main(String[] args) {
Test t = new Test();
synchronized(t) {
synchronized(t) {
System.out.println("made it!");
}
}
}
}
prints:
made it!
This example would deadlock if a single thread were not permitted to lock a lock more than once.

 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a single thread was not be able to acquire the same lock multiple times, it would not be permitted to invoke a synchronized method from the body of another synchronized method of the same class. In clear, one thread is allowed to lock the same lock multiple times. The lock is released when a equal amount of unlock actions have been performed.
Please refer to JLS 17.5 Rules about Locks for detailed information about how un/locking works.
reply
    Bookmark Topic Watch Topic
  • New Topic