1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 05:52:06 +01:00

sinttest: Use Thread.sleep(15) instead of Thread.yield()

Guus reports that the entity caps sinttest fails on openfire with an
timeout exception on Java 11. Very well possible that this is caused
by a changed scheduling behavior where the yield() thread nevertheless
dominates the, potential single, core.

The waitUntilThread() method is essentially a broken approach anyway
and should be replaced in the future.
This commit is contained in:
Florian Schmaus 2020-04-07 16:58:21 +02:00
parent 398cba330b
commit 3b27eb520f

View file

@ -61,14 +61,13 @@ public abstract class AbstractSmackIntTest {
} }
} }
@SuppressWarnings("ThreadPriorityCheck")
protected void waitUntilTrue(Condition condition) throws TimeoutException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { protected void waitUntilTrue(Condition condition) throws TimeoutException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final long deadline = System.currentTimeMillis() + timeout; final long deadline = System.currentTimeMillis() + timeout;
do { do {
if (condition.evaluate()) { if (condition.evaluate()) {
return; return;
} }
Thread.yield(); Thread.sleep(15);
} while (System.currentTimeMillis() <= deadline); } while (System.currentTimeMillis() <= deadline);
throw new TimeoutException("Timeout waiting for condition to become true. Timeout was " + timeout + " ms."); throw new TimeoutException("Timeout waiting for condition to become true. Timeout was " + timeout + " ms.");
} }