I have this code in Java:
public void doSomeThing() {
synchronized (this) {
doSomeThingElse();
}
}
public void doSome
You have already taken the monitor lock in the first synchronized. You should always ensure that the concurrency design does not make the performance impact huge.
One way to ensure this is by synchronizing only the required statements/code.
Let's say now your code will look something like this.
public void doSomeThing()
{
synchronized (this)
{
synchronized (this)
{
// do something else
}
}
}
Whereas this is what is required
public void doSomeThing()
{
doSomeThingElse();
}
public void doSomeThingElse()
{
synchronized (this)
{
// do something else
}
}