Skip to content
Advertisement

Adjust context switch frequency in Java on Linux

I’m looking into a potential concurrency issue in some binary Java code. The code sometimes has a strange behavior, but I’m not sure if it’s actually due to concurrency issues in the code itself, or if it’s something else. I haven’t been able to reproduce the strange behavior myself, but only seen it happening in our log files.

Is there a way to up the context switch frequency of the JVM, in order to surface potential concurrency issues with higher probability? Preferably doing this without explicitly inserting calls to Thread::yeild or Thread::sleep in the code.

Advertisement

Answer

I think the Thread-weaver test framework can help you. It’s been a while since I’ve experimented with it, but it does allow you to force a particular scheduling. It can also be run in a sort of default mode where a lot of interleavings between two methods are tested.

This is a simple example test (using default interleaving)

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement