Added the Code Samples
This commit is contained in:
parent
556a51175e
commit
56c231c662
@ -34,4 +34,20 @@ public class BaeldungSychronizedBlockUnitTest {
|
|||||||
assertEquals(1000, BaeldungSynchronizedBlocks.getStaticCount());
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user