question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Thread.sleep may be interrupted

See original GitHub issue

https://github.com/awaitility/awaitility/blob/8a33d4805d115c489fb914f9372e3ff36a0cbf7b/awaitility/src/main/java/org/awaitility/core/ConditionAwaiter.java#L81-L83

When trying out G1’s -XX:+UseStringDeduplication to reduce string memory bloat in my unit test reporter, I receive InterruptedException. The sleeper does not handle that case, though it is well documented. Perhaps consider implementing something like Guava’s Uninterruptibles#sleepUninterruptibly instead?

Caused by: java.lang.InterruptedException: sleep interrupted
	at java.lang.Thread.sleep(Native Method)
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:82)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:79)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:27)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:902)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:860)
	at com.github.benmanes.caffeine.cache.IsValidBoundedLocalCache.checkReadBuffer(IsValidBoundedLocalCache.java:89)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
ben-manescommented, Aug 18, 2019

You would have one thread waiting on a condition and then call Thread.interrupt() on another thread. You might look at Guava’s test code for Uninterruptibles, which does these types of things.

For my tests, the following command runs 323k tests fine on TestNG 6.14.3 in about 2 minutes.

./gradlew :caffeine:strongKeysAndStrongValuesAsyncCaffeineTest

It fals as shown with 7.0.0, as reported in https://github.com/cbeust/testng/issues/2096. I have tried to reduce memory usage on my side, but the cause is in their report handling. This triggers full GCs and increases the execution time to 4 minutes. However thanks to your fixes it now passes rather than having test failures. I don’t know when/if I can upgrade testng in this state, but that’s not your problem and I have to work it out with them.

You can play with this patch if interested.

0reactions
johanhalebycommented, Aug 18, 2019

I’ve tried to fix this, although I couldn’t simply copy code from Guava now so I’m not sure if it actually works. Published a new snapshot! Can you think of a test case that I can use to verify that the uninterruptible stuff is actually working?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interrupting a Thread in Java - GeeksforGeeks
interrupt () method: If any thread is in sleeping or waiting for a state then using the interrupt() method, we can interrupt the...
Read more >
Thread Sleeping and interrupting (Beginning Java forum at ...
Both sleep() and interrupted() are static methods .Both creates effect on the currently executing thread.. The Thread.sleep() method ...
Read more >
Pausing and interrupting threads | Microsoft Learn
Sleep with a value of Timeout.Infinite causes a thread to sleep until it is interrupted by another thread that calls the Thread.Interrupt method ......
Read more >
Thread.sleep() in Java - DigitalOcean
Thread.sleep() doesn't lose any monitors or lock the current thread it has acquired. Any other thread can interrupt the current thread in sleep, ......
Read more >
Thread Sleep() Method In Java With Examples
#4) The current thread that is in sleep can be interrupted by any other thread. In this case, “InterruptedException” is thrown.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found