Colin D
Colin D

Reputation: 5661

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.

Upvotes: 4

Views: 2381

Answers (3)

Ralf H
Ralf H

Reputation: 1474

There should be an item Filtering in the breakpoint properties dialog. There, you can limit the breakpoint to specific threads. But this only works when the program is already running since that dialog shows all threads from the running JVM.

Upvotes: 2

gpl
gpl

Reputation: 2995

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.

Upvotes: 7

mikołak
mikołak

Reputation: 9705

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.

Upvotes: 4

Related Questions