4 ms·
> The fact that you can synchronize on literally any object means that your object lock is effectively part of your public API I'd argue that the fact you can
by kmiroslav 10y ago
> The fact that you can synchronize on literally any object means that your object lock is effectively part of your public API
I'd argue that the fact you can lock on any object is a strength. These days, hardly any Java developer will use synchronized on methods and instead prefer the idiom:
public class A {
private Object lock = "";
public void foo() {
synchronized(lock) {
}
}
This allows Java code to be extremely granular in what gets locked, which has enabled very powerful multithreaded constructs and libraries such as ForkJoinPool and many others described in the Java Concurrency In Practice book.