Added the Code Samples

This commit is contained in:
Ali Dehghani 2020-06-20 13:50:49 +04:30
parent 556a51175e
commit 56c231c662
1 changed files with 16 additions and 0 deletions

View File

@ -34,4 +34,20 @@ public class BaeldungSychronizedBlockUnitTest {
assertEquals(1000, BaeldungSynchronizedBlocks.getStaticCount());
}
@Test
public void givenHoldingTheLock_whenReentrant_thenCanAcquireItItAgain() {
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");
}
}
}
}
}