Question

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 can concurrently invoke the same method.

Could to declare methods as synchronized be a good solution?

Thanks

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top