How to debug this? I know this is not thread safe, but just want to keep track of the logic.
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);
}
When it's executed to a.start(), in Eclipse I click "step into", it doesn't go to the run() method, but go to below, and there is no way to go to run() in my code. How to debug this?
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);
}
}