Threading in Java: How to lock an object?

前端 未结 7 697
长发绾君心
长发绾君心 2020-12-29 03:33

The following Function is executing in its own thread:

private void doSendData()
{
    try {

           //writeToFile(); // just a temporary location of a c         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 04:17

    In order to call wait() on an object, you have to hold the synchronized lock on that object (though the lock is actually released while the thread is waiting):

    synchronized (serverAddr) {
      serverAddr.wait();
    }
    

    I have to admit that why you're wanting to do this baffles me in this case...

提交回复
热议问题