Por que usar um ReentrantLock se alguém pode usar sincronizado (isso)?
Estou tentando entender o que torna o bloqueio na simultaneidade tão importante se pudermos usarsynchronized (this)
. No código fictício abaixo, posso fazer o seguinte:
Código:
private final ReentrantLock lock = new ReentrantLock();
private static List<Integer> ints;
public Integer getResult(String name) {
.
.
.
lock.lock();
try {
if (ints.size()==3) {
ints=null;
return -9;
}
for (int x=0; x<ints.size(); x++) {
System.out.println("["+name+"] "+x+"/"+ints.size()+". values >>>>"+ints.get(x));
}
} finally {
lock.unlock();
}
return random;
}