如何调试这个?我知道这不是线程安全的,但只是想跟踪逻辑。
class Test {
public static int count = 0;
class CountThread extends Thread {
public void run()
{
System.out.println(Thread.currentThread().getName() + " start");
count++;
System.out.println(Thread.currentThread().getName() + " end");
}
}
public void add(){
CountThread a = new CountThread();
CountThread b = new CountThread();
a.start();
b.start();
try {
a.join();
b.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
Test test = new Test();
System.out.println("START = " + Test.count);
test.add();
System.out.println("END: Account balance = " + Test.count);
}
当它执行到a.start()时,在Eclipse中我点击“step into”,它不会去run()方法,而是去下面,在我的代码中没有办法去run() . 如何调试这个?
public synchronized void start() {
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* to this method in the future may have to also be added to the VM.
*
* A zero status value corresponds to state "NEW".
*/
if (threadStatus != 0 || this != me)
throw new IllegalThreadStateException();
group.add(this);
start0();
if (stopBeforeStart) {
stop0(throwableFromStop);
}
}