Hi,
I have a class ThreadBO which starts 5 threads. Each thread is supposed to call a synchronized method 'IncrementVolCount()' which just increments a count variable & return the count variable to the thread. A stub code is given below. But when i run this i see that mutilple threads prints the same count. Could you please let me know if there's anything wrong in the way i have implemented synchronization/threading?
public class ThreadBO{
public void compute(){
//Create & Start Volume thread Objects.
volThreadObj = new RSThread[5];
for(int intThreadCount=0;intThreadCount<5;intThreadCount++){
volThreadObj[intThreadCount] = new RSThread();
volThreadObj[intThreadCount].start();
}
}
}
public class RSThread extends Thread{
public void run() {
count = intUtilObj.IncrementVolCount();
System.out.println(Count);
}
}
public class InterfaceUtils {
public static int intVolCount=-1;
public synchronized int IncrementVolCount() {
return ++intVolCount;
}
}