Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop at breakpoints only in certain thread

I have some multithreaded code and am trying to set up some breakpoints in Eclipse so I can do some debugging.

The breakpoint I want to set is in a class used by all of the threads. However, I only want the breakpoint to be hit when I am in the main thread. Is there a way to do this in Eclipse?

I have tried to use the 'conditional' breakpoint options but cannot get it to work.

like image 829
Colin D Avatar asked Sep 01 '25 22:09

Colin D


2 Answers

Conditional breakpoint approach is good. The condition should looks like: Thread.currentThread().getName().equals("main").

If you want to set up a breakpoint for another thread you just have to change "main" to a thread-specific name, which can be provided via the Thread constructor.

like image 135
gpl Avatar answered Sep 03 '25 20:09

gpl


You should be able to set up a conditional breakpoint by using a condition dependent on thread-local data. Two examples:

  • Thread.currentThread().getName(),
  • some value stored in a ThreadLocal.
like image 20
mikołak Avatar answered Sep 03 '25 20:09

mikołak