Summary
Add -XX:UserThreadWaitAttemptsAtExit=<number_of_waits>
flag to override the default max timeout (300 ms
) to wait for user threads to stop executing native code during JVM exit.
Problem
During JVM shutdown, if there are any user threads executing in native code, the JVM waits for those threads to return to the JVM. The maximum wait time is currently hardcoded to 300 milliseconds. The delay is not always necessary and the JVM can safely shutdown without waiting for the user threads in some environments.
Solution
Introduce a -XX:UserThreadWaitAttemptsAtExit=<number_of_waits>
flag. The flag is to specify the number of times to wait for user threads to stop executing native code during JVM exit. Each wait lasts 10 milliseconds. The maximum number of waits is 1000, to wait at most 10 seconds.
Specification
--- a/src/hotspot/share/runtime/globals.hpp
+++ b/src/hotspot/share/runtime/globals.hpp
@@ -836,10 +836,10 @@ const int ObjectAlignmentInBytes = 8;
"first occurrence of an out-of-memory error thrown from JVM") \
\
product(intx, UserThreadWaitAttemptsAtExit, 30, \ \
+ "The number of times to wait for user threads to stop executing " \
+ "native code during JVM exit. Each wait lasts 10 milliseconds. " \
+ "The maximum number of waits is 1000, to wait at most 10 " \
+ "seconds.") \
range(0, 1000) \
By default, UserThreadWaitAttemptsAtExit
is 30
, and the JVM may wait up to 300
milliseconds for user threads to stop executing native code when the JVM is exiting. That is the same as the existing behavior.
- csr of
-
JDK-8314243 Make VM_Exit::wait_for_threads_in_native_to_block wait for user threads time configurable
-
- Resolved
-