开发者

Release locks on crash in Java

I am writing a client-server application using Java-RMI. Some server-side ressources have to be accessed in mutual exclusion (I am using locks for that purpose).

开发者_C百科

Now I was wondering what happens when:

  1. The client calls a remote method on the server
  2. The remote method acquires a lock for a critical section
  3. The client crashes before the remote method exits the critical section

Will any locks acquired by the remote method call associated to that client be released? Or will it just be impossible for other clients to acquire the lock afterwards?

Thanks for your answers


What happens is that the remote method keeps executing until it is done, and releases the locks when it exits the critical section. Then it attempts to return the results (if any) to the client, and fails because the connection has been broken.

There is no particular hazard here ...

Of course, if the server is using Lock objects rather than primitive locks / mutexes, then it needs to do the lock releases in a finally block to deal with the case where it fails due to some unexpected exception. But this is a different issue. The client crashing won't trigger that scenario.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜