From 56c231c662b155cdc5ea9780d4fd8ace7cd7edb0 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sat, 20 Jun 2020 13:50:49 +0430 Subject: [PATCH] Added the Code Samples --- .../BaeldungSychronizedBlockUnitTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockUnitTest.java index 553b8c9906..40ed0549a2 100644 --- a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockUnitTest.java +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockUnitTest.java @@ -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"); + } + } + } + } + }