Thread.sleep may be interrupted
See original GitHub issueWhen 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:
- Created 4 years ago
- Comments:8
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.
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?