Skip to content

Commit 2b6976a

Browse files
Optimized ReadWriteLock
1 parent 2b082ef commit 2b6976a

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/concurrency/ReentrantJavaReadWriteLock.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class ReentrantJavaReadWriteLock implements ReadWriteLock
3030
{
31-
private transient volatile ReentrantReadWriteLock mutex;
31+
private final transient ReentrantReadWriteLock mutex = new ReentrantReadWriteLock();
3232

3333
public ReentrantJavaReadWriteLock()
3434
{
@@ -37,23 +37,7 @@ public ReentrantJavaReadWriteLock()
3737

3838
private ReentrantReadWriteLock mutex()
3939
{
40-
/*
41-
* Double-checked locking to reduce the overhead of acquiring a lock
42-
* by testing the locking criterion.
43-
* The field (this.mutex) has to be volatile.
44-
*/
45-
ReentrantReadWriteLock mutex = this.mutex;
46-
if(mutex == null)
47-
{
48-
synchronized(this)
49-
{
50-
if((mutex = this.mutex) == null)
51-
{
52-
mutex = this.mutex = new ReentrantReadWriteLock();
53-
}
54-
}
55-
}
56-
return mutex;
40+
return this.mutex;
5741
}
5842

5943
/**

0 commit comments

Comments
 (0)