Hi Jofer,
the RemoteDataAccessFactoryInterface interface receive RemoteDataAccessImplement class,the RemoteDataAccessImplement class is a adapter,it implement RemoteDataAccessInterface and extends DBAccess interface,the Data class also implements DBAccess interface.
Sorry, just trying to get a bit of clarification here...
Does the RemoteDataAccessFactoryImplement class create instances of the RemoteDataAccessImplement class?
when the Server class is running,the MultiClient can connection the Server at one time,Why use MultiThread?
Are you talking about a class named MultiThread? Or are you talking about multi threading as a concept.
The good thing about RMI is that it creates multiple threads for you.
The bad thing about RMI is that it creates multiple threads for you.
Simply because you are using RMI, your code instantly can have multiple threads running on it. Therefore you must make your code
thread safe.
Consider the following code:
When I ran it, this is the output I got:
Note that I deliberately started and identified 4 client threads. RMI started (at least) 4 server threads - all running on the single instance of the Server() class.
And as you can (hopefully) see, the
instance variable
counter is not thread safe and is not being used in thread safe classes - clients 1 & 3 found a different value in
counter at the end of their execution of the server code than when they started.
Regards, Andrew