3

Is it possible to synchronize all the events happening for a group of channels in netty.I have tried to achieve this using OrderedMemoryAwareThreadPoolExecutor, but not all events are synchronized. Could you please suggest any methods to synchronize all events for a group of channels.

Thank you

4

1 回答 1

1

我相信你想要的在java中被称为条件。

初始化

final Lock lock = new ReentrantLock();
final Condition cond  = lock.newCondition(); 

在您使用的所有功能中,您需要先锁定锁,并确保您可以释放它:

lock.lock();
try {
  // do you stuff...
} finally {
    lock.unlock();//interrupt or not, release lock
}     

在所有你想等你的地方打电话

cond.await();

当所有需要继续的条件都得到满足时,你打电话

cond.signal();
于 2013-03-26T09:58:24.490 回答