Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suspending the JVM for a limited amount of time

Tags:

java

jvm

How can I suspend the execution of a JVM for a configurable amount of time, similar to want happens on a full, serial, Garbage Collection? I want to test some edge cases but it's difficult to create the exact pauses I need with manually generating garbage + System.gc().


I'm trying to 'freeze' all the threads in the application, to simulate a situation where an application becomes unresponsive, and then resumes execution. The application is part of a cluster, and I'm trying to debug some leave / join / re-join problems.

like image 290
Robert Munteanu Avatar asked Oct 27 '25 14:10

Robert Munteanu


1 Answers

JVM suspend can be done from command line with jdb:

jdb -attach 8787
Initializing jdb ...
> suspend
All threads suspended.
> resume
All threads resumed.
> exit

But this requires it to be started with -Xdebug ...

There is also universal way to suspend and resume any process on Linux/Unix:

kill -SIGSTOP PID
kill -SIGCONT PID

See also How to suspend/resume a process in Windows?

like image 184
Vadzim Avatar answered Oct 29 '25 04:10

Vadzim