I have written below mentioned code and i am expecting 12000 as an answer. however not getting correct answer. for every run i get some new number
package thread;
public class ThreadExp extends Thread {
static volatile int count=0;
public synchronized void increment() {
count++;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ThreadExp a = new ThreadExp();
a.start();
ThreadExp a1 = new ThreadExp();
a1.start();
try {
a.join();
a1.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(count);
}
public void run() {
for(int i=1; i<=6000 ;i++) {
increment();
}
}
}