/** {@inheritDoc} */ @Override public void run() { // In case of ordered messages this may be called twice for 1 message. // Example: message arrives, but listener has not been installed yet. // Message set is created, but message does not get actually processed. // If this is not called, connection may be paused which causes hang. // It seems acceptable to have the following logic accounting the aforementioned. int cnt = 0; for (;;) { int cur = msgCnt.get(); if (cur == 0) break; cnt = cur - 1; if (msgCnt.compareAndSet(cur, cnt)) break; } assert cnt >= 0 : "Invalid count [cnt=" + cnt + ", this=" + this + ']'; if (cnt < msgQueueLimit && paused && lock.tryLock()) { try { // Double check. if (paused && msgCnt.get() < msgQueueLimit) { ses.resumeReads(); paused = false; } } finally { lock.unlock(); } } }
/** {@inheritDoc} */ @Override public void run() { // In case of ordered messages this may be called twice for 1 message. // Example: message arrives, but listener has not been installed yet. // Message set is created, but message does not get actually processed. // If this is not called, connection may be paused which causes hang. // It seems acceptable to have the following logic accounting the aforementioned. int cnt = 0; for (;;) { int cur = msgCnt.get(); if (cur == 0) break; cnt = cur - 1; if (msgCnt.compareAndSet(cur, cnt)) break; } assert cnt >= 0 : "Invalid count [cnt=" + cnt + ", this=" + this + ']'; if (cnt < msgQueueLimit && paused && lock.tryLock()) { try { // Double check. if (paused && msgCnt.get() < msgQueueLimit) { ses.resumeReads(); paused = false; } } finally { lock.unlock(); } } }