mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 11:38:00 +01:00
[core] Fix busy-loop in SmackReactor
Fixes SMACK-938.
This commit is contained in:
parent
0fb8bfdf6c
commit
390f6f0fa7
1 changed files with 6 additions and 0 deletions
|
@ -327,6 +327,12 @@ public class SmackReactor {
|
|||
|
||||
int currentReactorThreadCount = reactorThreads.size();
|
||||
int myKeyCount = pendingSelectionKeysSize / currentReactorThreadCount;
|
||||
// The division could result in myKeyCount being zero, even though there are pending selection keys.
|
||||
// Therefore, ensure that this thread tries to get at least one pending selection key by invoking poll().
|
||||
// Otherwise, it could happen that we end up in a busy loop, where myKeyCount is zero and this thread invokes
|
||||
// selector.wakeup() below because pendingSelectionsKeys is not empty, but the woken up reactor thread wil
|
||||
// end up with myKeyCount being zero again, restarting the busy-loop cycle.
|
||||
if (myKeyCount == 0) myKeyCount = 1;
|
||||
Collection<SelectionKey> selectedKeys = new ArrayList<>(myKeyCount);
|
||||
for (int i = 0; i < myKeyCount; i++) {
|
||||
SelectionKey selectionKey = pendingSelectionKeys.poll();
|
||||
|
|
Loading…
Reference in a new issue