B
Brian
I have a method on an RMI server, and this method changes a state variable.
I don't want multiple RMI clients to modify this variable concurrently (i.e.
by calling the method on their stub).
Should I make the method synchronized? Is this class thread-safe?
The class is shown below.
public class RMIServer extends UnicastRemoteObject
implements ServerInterface {
private int state = 0;
RMIServer() throws Exception {
super();
String rmiObjectName =
"rmi://"+ InetAddress.getLocalHost() + "/RMIServer";
Naming.rebind(rmiObjectName, this);
}
public void update_state(int increment){
state = state + increment;
}
}
I don't want multiple RMI clients to modify this variable concurrently (i.e.
by calling the method on their stub).
Should I make the method synchronized? Is this class thread-safe?
The class is shown below.
public class RMIServer extends UnicastRemoteObject
implements ServerInterface {
private int state = 0;
RMIServer() throws Exception {
super();
String rmiObjectName =
"rmi://"+ InetAddress.getLocalHost() + "/RMIServer";
Naming.rebind(rmiObjectName, this);
}
public void update_state(int increment){
state = state + increment;
}
}