someone please check my lock logic and let me know if there are any flaws.
boolean lock=true;
public void lock(num) {
synchronized(vector) {
if( (vector.containsKey(new Integer(num))) ||
(vector.containsKey(new Integer(-1))) ||
(! lock)) {
try {
vector.wait();
} catch(InterruptedException ie) {
}
while (lock) {
while((vector.size() > 0) & (num == -1)) {
lock = false;
try {
vector.wait();
} catch(InterruptedException ie) {
}
vector.put(new Integer(num), "true");
//notifyAll();
break;
}
}
}
}
}
boolean lock=true;
public void lock(num) {
synchronized(vector) {
if( (vector.containsKey(new Integer(num))) ||
(vector.containsKey(new Integer(-1))) ||
(! lock)) {
try {
vector.wait();
} catch(InterruptedException ie) {
}
while (lock) {
while((vector.size() > 0) & (num == -1)) {
lock = false;
try {
vector.wait();
} catch(InterruptedException ie) {
}
vector.put(new Integer(num), "true");
//notifyAll();
break;
}
}
}
}
}