another workaround for register/select wonkiness. patch by jbellis; tested by Mark Robson for CASSANDRA-156

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@774076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2009-05-12 20:46:36 +00:00
parent da441aed29
commit 3aca0737cb
1 changed files with 11 additions and 5 deletions

View File

@ -32,6 +32,9 @@ public class SelectorManager extends Thread
// the underlying selector used
protected Selector selector;
// workaround JDK select/register bug
Object gate = new Object();
// The static selector manager which is used by all applications
private static SelectorManager manager;
@ -71,12 +74,14 @@ public class SelectorManager extends Thread
public SelectionKey register(SelectableChannel channel,
SelectionKeyHandler handler, int ops) throws IOException
{
if ((channel == null) || (handler == null))
{
throw new NullPointerException();
}
assert channel != null;
assert handler != null;
return channel.register(selector, ops, handler);
synchronized(gate)
{
selector.wakeup();
return channel.register(selector, ops, handler);
}
}
/**
@ -91,6 +96,7 @@ public class SelectorManager extends Thread
{
selector.select(100);
doProcess();
synchronized(gate) {}
}
catch (IOException e)
{