Can anyone tell me which one is better approach between synchronization method and private final object in java and why ??
public class kclass {
private final Object myObject = new Object();
public synchronized void show() {
...
}
public void show1() {
synchronized(myObject) {
...
}
}
}
synchronized
andprivate
do completely different things. What actual problem are you trying to solve? Could you please edit your question with more background?synchronized method() { ... }
andmethod() { synchronize (obj) { ... } }
with aprivate final Object obj;