Java Reference
In-Depth Information
System.exit(0);
}
public void run() {
try {
ServerReference remoteCode =
(ServerReference) Naming.lookup("RmiProblem");
for (int i = 0; i < 5; i++) {
remoteCode.serverThreadNumber(getName());
Thread.sleep(2000);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}
Don't worry if you do not understand this code completely. Chapter 6 discusses RMI in
depth, so it may be easier to come back to this code after reading that chapter.
Although the results of running this code will vary from computer to computer (and
indeed from run to run), one example of running the code is shown in Figure 5-7.
Figure 5-7. Example of thread reuse within RMI
As can be seen in Figure 5-7, both client A and client B use threads 15655788 and
16112134.
With this in mind, if we cannot use tokens and we have chosen to use RMI, then we need
to find some other way of uniquely identifying our clients.
One way of handling this is to build our server using the Factory design pattern, where
our factory creates a unique object for each connected client. We can then use the unique
instance of our DvdDatabase class to identify the client.
Search WWH ::




Custom Search