0
考慮以下行的LinkedBlockingQueue下同步嵌套,活鎖問題
public Result doSomething(Service srv) throws InterruptedException
{
synchronized(srv)
{
if (this._registeredServices.containsKey(srv.getId()))
{
return this._queue.get(srv.getId()).take();
}
throw new IllegalStateException();
}
}
其中this._queue
與
private ConcurrentHashMap<String, LinkedBlockingQueue<Result>> _queue;
幾個線程正在使用的同步過程的訪問來自不同的地方srv
實現。
我的問題是,我可以進入livelock wheras take
方法正在等待數據並仍然保持srv
鎖,或者它釋放它直到它有一個值,然後嘗試重新抓住它繼續之前?