Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I synchronize the events for a group of channels in Netty...?

Tags:

java

netty

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

like image 633
user2067201 Avatar asked Dec 06 '25 08:12

user2067201


1 Answers

I believe that what you want is called a Condition in java.

Initialize with

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

In all functions you use is you need to lock the lock first, and make sure that you can release it:

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

In all places where you want to wait you call

cond.await();

And when all conditions need to continue have been met you call

cond.signal();
like image 142
fredrik Avatar answered Dec 08 '25 22:12

fredrik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!