Merge pull request #9529 from alimate/BAEL-4272
BAEL-4272: Reentrant Synchronized Blocks
This commit is contained in:
commit
7b0332e00c
|
@ -34,4 +34,20 @@ public class BaeldungSychronizedBlockUnitTest {
|
||||||
assertEquals(1000, BaeldungSynchronizedBlocks.getStaticCount());
|
assertEquals(1000, BaeldungSynchronizedBlocks.getStaticCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenHoldingTheLock_whenReentrant_thenCanAcquireItAgain() {
|
||||||
|
Object lock = new Object();
|
||||||
|
synchronized (lock) {
|
||||||
|
System.out.println("First time acquiring it");
|
||||||
|
|
||||||
|
synchronized (lock) {
|
||||||
|
System.out.println("Entering again");
|
||||||
|
|
||||||
|
synchronized (lock) {
|
||||||
|
System.out.println("And again");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue