-
When make more fair to prevent starvation in java using lock instead of declare synchronized function
it can not instantiate the type Lock -
do it need to implement FairLock like http://tutorials.jenkov.com/java-concurrency/starvation-and-fairness.html
do java’s lock equal FairLock above? It said FairLock will slow performance, what will it be in real practiceLock lock = new Lock();
When make more fair to prevent starvation in java using lock instead of declare
Share
You’re probably trying to instantiate a java.util.concurrent.locks.Lock, which is an interface. That won’t work of course. You’ll want to instantiate an implementation, such as ReentrantLock, which is pretty much the standard way of doing “flexible” locks in Java, in cases where simple monitor locks aren’t sufficient. Its documentation has something to say about fairness: