...
Code Block | ||
---|---|---|
| ||
public class SomeObject {
public synchronized void changeValue() { // Locks on the class object's monitor
// ...
}
}
// Untrusted code
synchronized (someObject) {
while (true) {
Thread.sleep(Integer.MAX_VALUE); // Indefinitely delay someObject
}
}
|
...
Code Block | ||
---|---|---|
| ||
public class SomeObject {
private final Object lock = new Object(); // private lock object
public void changeValue() {
synchronized (lock) { // Locks on the private Object
// ...
}
}
}
|
...