All that synchronized means is that only one thread at a time may execute that code for that instance.
I don't quite understand the question about the client: surely the client won't call the method, the web server will do that? Without some ocde or more details I can't really answer the question.
no actually the client will call the method because I am using rmi.
eg a login and regstering function on the server which takes a players name . The client fills his name on the screen and invokes the method on the server.
Now many clients can cal lthe server simultaenously.
So does the method has to be synchronised. Now if the object (client ) that calls the method is not a thread ,
and I put
synchronised public void register()
will it take care of only one client being active in the method at a time.
i think
the synchronization will be done for all the callers
either directly a thread or not
because any call that you make is a seprate runnig sequence of instructions
try this code
whith two different calls to print and print1 Methods
public class Test {
public Test() {
Thread th1=new Thread(new Runner());
Thread th2=new Thread(new Runner());
th2.start();
th1.start();
print(3);
}
public static void main(String[] args) {
Test theradTest = new Test();
}
int i=0;
class Runner implements Runnable{
public void run(){
print(i++);
}
}
synchronized void print(int j){
for (int i=0;i<100;i++)
System.out.println("i"+i+"j"+j);
}
void print1(int j){
for (int i=0;i<100;i++)
System.out.println("i"+i+"j"+j);
}
}
1. If the clients are not threads, they can only access the object 1 at a time anyway.
2. You can consider a seperate running process (client) as a Seperate thread, because it is.
3. I dont think RMI allows simultaneous invocation anyway, so your RMI server will only allow 1 client at a time to invoke a method.
4. Putting synchronized will INSURE that the synchronized resource can only be accesses by 1 at a time, but I am almost positive this will be redundent.