Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deprioritize Java testrunner in Eclipse breakpoints?

If I am debugging some multithreaded Java code in Eclipse - with a main class RunTest, and an interesting class QueueListener.

Assumptions:

  • When RunTest is initialized - QueueListener runs in the background.
  • When RunTest finalises - QueueListener is terminated
  • There is a single method in RunTest - with a breakpoint in it
  • There is a single method in QueueListener with a breakpoint in it
  • QueueListener can run over and over again
  • RunTest only runs once per execution (parent class)

When debugging in Eclipse - both breakpoints come up. But Eclipse gives priority to RunTest - and I have to manually flip it over to the QueueListener by selecting that thread in the debugger - and keep repeating this over and over.

Is there a way to tell Eclipse that I'm more interested in the QueueListener, and consider the testrunner to be a lower priority - when it chooses debug breakpoints to show?

like image 349
hawkeye Avatar asked Mar 28 '13 12:03

hawkeye


People also ask

How do I fix Java exception breakpoint in Eclipse?

You can fix this immediately by opening the Markers view and delete the Java Exception Breakpoints. However, to permanently remove this type of breakpoints, you have to go to the Java Debug options and uncheck the "Suspend excecution on uncaught exceptions" option.

How do I toggle between breakpoints in Eclipse?

To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively, you can double-click on this position. The Breakpoints view allows you to delete and deactivate Breakpoints and modify their properties.

Why breakpoints are not working in Eclipse?

The solution was to enable it again, start a debug session, the breakpoint is hit and shown in the UI, then disable again the option. There is also another simpler way that will make Eclipse show the debugging highlight at the breakpoint or rather refresh the debugging UI to work as it should.


1 Answers

The answer can be found in the eclipse source code within the ThreadEventHandler method. There is a queue of suspended threads, as below:

/**
 * Queue of suspended threads to choose from when needing
 * to select a thread when another is resumed. Threads
 * are added in the order they suspend.
 */
private Set fThreadQueue = new LinkedHashSet();

Further down, every time a breakpoint is hit, the suspended thread is added to this queue:

protected void handleSuspend(DebugEvent event) {
   ...
   queueSuspendedThread(event);
   ...
}

The method to get the next suspended thread is:

protected synchronized IThread getNextSuspendedThread() {
    if (!fThreadQueue.isEmpty()) {
        return (IThread) fThreadQueue.iterator().next();
    }
    return null;
}

So the answer is no, there is no control over the order, it will strictly be in the order that each thread hits the breakpoint and is added to the underlying queue.

like image 79
Joe Elleson Avatar answered Oct 05 '22 12:10

Joe Elleson