开发者

Java RMI: concurrency support

I am developing a multiplayer card game with a P2P architecture, it isn't a my decision, the project has been commissioned by the professor of Distributed System course at my University.

Another constraint imposed by the professor is to use Java RMI technology to implement the communication layer between the players.

i would know if Java RMI manages concurrency "out of the box", in other words I would know if when I invoke a method on a remote object, the object is automatically "locked" and no objects开发者_StackOverflow中文版 can concurrently invoke the same method.

Could to declare methods as synchronized be a good solution?

Thanks


Calling a method on a remote object does not lock the object.

Declaring a method to be synchronized is one way to control access. However simply declaring all of your methods on all of your remote-accessible objects to be synchronized is a bad idea. Indeed, depending on the details of what you are doing it could create unnecessary concurrency bottlenecks and/or the risk of deadlocks. You need to think more carefully about the behavior of the objects and the interactions.


Synchronizing your method is a good start. There is a performance penalty for doing this, but in your case this is perfectly fine.

Take a look at this Java RMI and synchronized methods

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜