Open rschildmeijer opened 13 years ago
one drawback -- its very dangerous to invoke this from the IOLoop. So maybe we need to check which thread is invoking the method.
Tried with j.u.c.CountDownLatch, works fine. Request for comments
Patch ready for review: https://gist.github.com/856549
Drawbacks. 1, Extremely dangerous to invoke the public jmx methods from the io loop thread. 2, premature optimization? I havent seen a CME in action (yet) because of interleaving threads in the jmx apis.
The current JMX usage is not thread safe. (The "jmx thread" is accessing methods on e.g IOLoop.)
One way to solve this is to use IOLoop.addCallback and explicit locking. e.g (semi pseudo, missing some try catch etc) @Override public int getNumberOfRegisteredIOHandlers() { //return handlers.size(); final Object lock = new Object(); // maybe a ReentrantLock is more appropriate final int[] rv = new int[1]; IOLoop.INSTANCE.addCallback(new AsyncCallback() { @Override public void onCallback() { rv[0] = handlers.size(); lock.notifyAll(); } } ); synchronized (lock) { lock.wait(); } return rv[0]; }