Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Simulate a hung thread in a multi threaded environment?

We have a Java multi threaded environment processing millions of records. In production, some threads have been observed to be hung, waiting for a synchronized method.. Work around was provided by removing dependency on synchronized method.

But, still unable to replicate the issue in Dev environment, that multiple threads are hung on a synchronized method. In Dev, all threads are completed in every attempt. Any suggestions how to replicate the issue in Dev to unit test the patch??

After more analysis, it seems the case of starvation.Any pointers on how to simulate starvation in executor framework ?

like image 810
Vijay Kumar Chauhan Avatar asked Feb 01 '26 23:02

Vijay Kumar Chauhan


1 Answers

In your DEV environment as you could not create a production like environment to re-create the bug you need to introduce a long sleep statement in the synchronize block, so that other threads must wait for a thread to complete that synchronize block. So just add a long sleep statement inside your synchronize block and try.

like image 98
Abhijit Pritam Dutta Avatar answered Feb 03 '26 12:02

Abhijit Pritam Dutta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!