Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Debug Thread.start() in java

I am debugging a Java Application in NetBeans IDE 8.0.2.

When a Thread.start() method is called I am not able to reach the run() method of that thread (though I put the breakpoints in that method). However, sometimes it is hitting the method but sometimes not.

How can I reach the run() method while debugging?

public class JavaApplication7 {

    public static void main(String[] args) {
        Mailthread1 mt1 = new Mailthread1();
        Thread pt = new Thread(mt1);
        pt.setName("Mailthread");
        pt.start();
    }
}

And the Thread class is :

class Mailthread1 implements Runnable {
    public void run() {
        System.out.println("Cant hit this line");
    }
}
like image 537
Anil Kumar Avatar asked Nov 09 '22 09:11

Anil Kumar


1 Answers

in the JDWP, there are 3 types of breakpoint: class, method and line.

If your IDE fails to intercept the line breakpoint in the println(), then you can try a method breakpoint on the run() reclaration.

If that fails, there is something out of sync between the byte code and the source. You can try adding lines, breakpointing another line above and below.

Other than that, change IDE and/or change JVM. This should work.

like image 83
user2023577 Avatar answered Nov 14 '22 23:11

user2023577