diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java index 1b8218832a4..9eb75a2d484 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java @@ -63,7 +63,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa private long _lowResourcesConnections; private SelectSet[] _selectSet; private int _selectSets=1; - private volatile int _set; + private volatile int _set=0; private boolean _deferringInterestedOps0=true; private int _selectorPriorityDelta=0; @@ -128,6 +128,8 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa // be distributed over the available sets. int s=_set++; + if (s<0) + s=-s; s=s%_selectSets; SelectSet[] sets=_selectSet; if (sets!=null) @@ -150,6 +152,8 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa // be distributed over the available sets. int s=_set++; + if (s<0) + s=-s; s=s%_selectSets; SelectSet[] sets=_selectSet; if (sets!=null) @@ -167,6 +171,8 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa public void register(ServerSocketChannel acceptChannel) { int s=_set++; + if (s<0) + s=-s; s=s%_selectSets; SelectSet set=_selectSet[s]; set.addChange(acceptChannel);