Skip to content

Commit 0692bac

Browse files
committed
BAEL-3855
1 parent dae03d6 commit 0692bac

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public SingleLock() {
1414

1515
protected Supplier<?> putSupplier(Map<String,String> map, int key) {
1616
return (()-> {
17+
lock.lock();
1718
try {
18-
lock.lock();
1919
return map.put("key" + key, "value" + key);
2020
} finally {
2121
lock.unlock();
@@ -25,8 +25,8 @@ protected Supplier<?> putSupplier(Map<String,String> map, int key) {
2525

2626
protected Supplier<?> getSupplier(Map<String,String> map, int key) {
2727
return (()-> {
28+
lock.lock();
2829
try {
29-
lock.lock();
3030
return map.get("key" + key);
3131
} finally {
3232
lock.unlock();

core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ protected Supplier<?> putSupplier(Map<String,String> map, int key) {
1717
return (()-> {
1818
int bucket = key % stripedLock.size();
1919
Lock lock = stripedLock.get(bucket);
20+
lock.lock();
2021
try {
21-
lock.lock();
2222
return map.put("key" + key, "value" + key);
2323
} finally {
2424
lock.unlock();
@@ -30,8 +30,8 @@ protected Supplier<?> getSupplier(Map<String,String> map, int key) {
3030
return (()-> {
3131
int bucket = key % stripedLock.size();
3232
Lock lock = stripedLock.get(bucket);
33+
lock.lock();
3334
try {
34-
lock.lock();
3535
return map.get("key" + key);
3636
} finally {
3737
lock.unlock();

0 commit comments

Comments
 (0)