Java synchronization method with expensive parameters

I have a synchronization method that seems to "use" synchronization significantly longer than it should be It looks like;

public static synchronized void myMethod(MyParameter p) {
    //body (not expensive)
}

The phone looks like;

myMethod(generateParameter());

Generateparameter () is known to be a very expensive (long time) call My idea is that when generateparameter () is executed, the mutex on mymethod class is blocked. What's going on? I found it a different debugging problem, but it seems to be happening

Solution

That's impossible; First, execute the generateparameter() call, and then give the result as the parameter of the mymethod call, and then the mymethod call will obtain the mutex

Will it take a long time, or will it stop indefinitely? (deadlock)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>