Reputation: 20139
Is there a way for the debugger to pause a specific thread while letting the other ones run? I want to verify some locks I have are working properly and Im not sure how to induce certain conditions. Note that all the threads run through the same code, so any changes to the code will affect all threads, where as I only want to stop one thread.
Upvotes: 2
Views: 1676
Reputation: 1750
You might want to look at testing frameworks like MultithreadedTC - which lets you programmatically control flow through the different threads during the test so you can cause race conditions and timeouts during testing.
Upvotes: 1
Reputation: 20139
I was able to sort of fix my own problem by basically putting the following code in the thread code -
if(Thread.currentThread.getName()="thread1"){
Thread.currentThread.sleep(5000);
}
This way only thread 1 sleeps. It worked well enough that I saw my locks working, but this isnt really a good solution I feel. Perhaps someone can make something better?
Upvotes: 0
Reputation: 2246
You can add a method to do a sleep in the thread. Then you can call that method with junit or a simple POJO.
Upvotes: 0
Reputation: 13907
If you have a convenient point in your code to set a breakpoint for that single thread, you can change the Suspend Policy
of that breakpoint in its properties to only stop the current thread instead of the whole VM.
Upvotes: 0