-
Notifications
You must be signed in to change notification settings - Fork 44
@WriteLock @ReadLock
peichhorn edited this page Jun 30, 2012
·
6 revisions
(Documentation pending)
import lombok.ReadLock;
import lombok.WriteLock;
import java.util.HashMap;
import java.util.Map;
public class LockExample {
private Map<String, String> dictionary = new HashMap<String, String>();
@WriteLock("dictionaryLock")
public void put(String key, String value) {
dictionary.put(key, value);
}
@ReadLock("dictionaryLock")
public String get(String key) {
return dictionary.get(key);
}
}
import java.util.Map;
import java.util.HashMap;
class LockExample {
private final java.util.concurrent.locks.ReadWriteLock dictionaryLock = new java.util.concurrent.locks.ReentrantReadWriteLock();
private Map<String, String> dictionary = new HashMap<String, String>();
public void put(final String key, final String value) {
this.dictionaryLock.writeLock().lock();
try {
dictionary.put(key, value);
} finally {
this.dictionaryLock.writeLock().unlock();
}
}
public String get(final String key) {
this.dictionaryLock.readLock().lock();
try {
return dictionary.get(key);
} finally {
this.dictionaryLock.readLock().unlock();
}
}
}
(Documentation pending)
Nothing to configure yet.
I am not able to run @Action. If I provide Action1 implementation it works.
implementation private static Action1 println() { return new Action1() { public void apply(final Object o) { System.out.println(o); } };
pom : com.github.peichhorn lombok-pg 0.11.3
<dependency>
<groupId>com.github.peichhorn</groupId>
<artifactId>lombok-pg</artifactId>
<version>0.11.3</version>
<classifier>runtime</classifier>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>