java “使用所有者方法的长时间监视器争用事件”的原因可能是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29073847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What might be the cause of "long monitor contention event with owner method"?
提问by Ahmed Samy
I'm a beginner and I have an assignment of making a basic chat app of two clients and a server exchanging strings which are destination+message.
我是一个初学者,我的任务是制作一个基本的聊天应用程序,两个客户端和一个服务器交换目的地+消息的字符串。
I have written some code, but when I use it I'm getting this "long monitor contention event with owner method" at the other end.
我已经编写了一些代码,但是当我使用它时,我在另一端收到了这个“使用所有者方法的长监视器争用事件”。
Can anyone help me with how this can occur? Or can anyone tell me the cause of this in general?
任何人都可以帮助我解决如何发生这种情况吗?或者谁能告诉我一般情况下的原因?
回答by Stephen C
It is caused by one thread holding a monitor / mutex for a long time, and blocking other threads. In this case, "a long time" is 100 milliseconds or more. (This pull requestis where this check was added.)
它是由一个线程长时间持有监视器/互斥锁并阻塞其他线程引起的。在这种情况下,“长时间”是 100 毫秒或更多。(此拉取请求是添加此检查的地方。)
It is a warning ... but you would be advised to look into it as it is likely to lead your application being unresponsive.
这是一个警告……但建议您查看它,因为它可能导致您的应用程序无响应。
In general, the cure is to reduce the length of time your application needs to hold mutexes. But, without seeing your code, it is hard to advise how you would do this.
通常,解决方法是减少您的应用程序需要保持互斥锁的时间长度。但是,在没有看到您的代码的情况下,很难建议您将如何执行此操作。