R
Robert Stark
I want to write a lock to control access to a resource, there are
different kind of jobs using this resource, say job A,B,C, at the
beginning, i use Lock api from jdk concurrent package, but i suffered
from serious job starvation, so i want to do something like this:
class T LockManager<T extends Enum>{
//the input is like this, A=>20, B=>70, C=>10, assign quota to
different jobs
public LockManager(Map<T,Integer> quota){
}
private void lock(T type){......}
private void unlock(T type){........}
public Lock getLock(T type){
return new QutaLock(type);
}
public class QutaLock implements Lock{
public QutaLock(T type){
.....
}
public void lock(){.....}
public void unlock(){.........}
......
}
}
My idea is input a map of percentages you want to assign for each job,
and provide a simple lock api.
Input A=>20, B=>70, C=>10 means A=>20%, B=>70%, C=>10%
If there's no A jobs pending on the lock, then its quota would be
divided evenly to other pending jobs that is B=>80%, C=>20%.(This rule
apply to other type of jobs as well).
Then i got stuck, the only way i can think about is to introduce an
extra dispatch thread and several queues, can someone give me some
hint?
different kind of jobs using this resource, say job A,B,C, at the
beginning, i use Lock api from jdk concurrent package, but i suffered
from serious job starvation, so i want to do something like this:
class T LockManager<T extends Enum>{
//the input is like this, A=>20, B=>70, C=>10, assign quota to
different jobs
public LockManager(Map<T,Integer> quota){
}
private void lock(T type){......}
private void unlock(T type){........}
public Lock getLock(T type){
return new QutaLock(type);
}
public class QutaLock implements Lock{
public QutaLock(T type){
.....
}
public void lock(){.....}
public void unlock(){.........}
......
}
}
My idea is input a map of percentages you want to assign for each job,
and provide a simple lock api.
Input A=>20, B=>70, C=>10 means A=>20%, B=>70%, C=>10%
If there's no A jobs pending on the lock, then its quota would be
divided evenly to other pending jobs that is B=>80%, C=>20%.(This rule
apply to other type of jobs as well).
Then i got stuck, the only way i can think about is to introduce an
extra dispatch thread and several queues, can someone give me some
hint?