Posted By:
Chandra_Patni
Posted On:
Monday, February 25, 2002 01:43 AM
You have to implement your own synchronization mechanism to do so.
A very simple implementation can be as follows. Note that you can write a lot more elegant way of doing it.
public class A {
private int count = 0;
public void method() {
if(getActiveThread() < 3) {
methodHelper();
}
}
private synchronized void methodHelper() {
i++;
// method implementation here.
i--;
}
private synchronized int getActiveThread() {
return i;
}
}