30

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?

J Richard Snape
  • 20,116
  • 5
  • 51
  • 79
Ahmed Samy
  • 1,006
  • 2
  • 11
  • 24
  • 1
    Hi - this question came to me in the review queue to try to improve its answerability. You need to add more detail to make this question more useful and easier to answer. In particular - a Minimal, complete and verifiable example ([http://stackoverflow.com/help/mcve](http://stackoverflow.com/help/mcve)) would help a lot here. You may well find that in making such an example (cutting down your code to make it minimal), you reveal the answer for yourself. – J Richard Snape Mar 16 '15 at 11:06
  • As per my other comment - you really need to add some infromation to make this question really useful and able to be answered in full. I've tried to point you in the right direction - I hope you can add some code where I have put "I have written some code". Otherwise, you will only get generic answers pointing you to why that error is thrown. Have a look at [How to ask](http://stackoverflow.com/questions/how-to-ask) in addition to the MCVE link. Good Luck! – J Richard Snape Mar 16 '15 at 11:10
  • 1
    I just want to point out that for people *other than* the OP, a generic answer may well be *more* helpful than one that is specific to the OP's code. – Stephen C Dec 02 '21 at 07:45

1 Answers1

37

It is caused by one thread holding a monitor / mutex for a long time, and blocking other threads. For example:

synchronized(lock) {
    /* do something that takes a long time */
}

In this case, "a long time" is 100 milliseconds or more. (This pull request is where this check was added.)

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.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216