COMP 310
|
Lec44: Tips & Traps and Team Work |
![]() ![]() ![]() ![]() ![]() ![]() |
Watch out for code that attempts to perform RMI actions before IRMIUtils.startRMI() has been run! Symptoms can include strange RMI behavior such as remote dynamic class loading not working as expected. Common culprit: constructors that try to do too much, too early.
Tip:
Not waiting for network operations to complete can lead to race conditions such as concurrent modification errors. Common culprit: A method that sends the data to the a chat room on a new thread but provides no means of executing a process after the returned packets have been processed, i.e. after the data has been definitively sent.
Tips:
Shutting down the application leaves objects still bound in the Registry, network connections hanging or disconnected, class file servers still running, etc. Common culprit: A main GUI frame that is set to EXIT_ON_CLOSE and thus does not "clean-up" before it exits, e.g. gracefully exit all chat rooms, run IRMIUtils.stopRMI() to shut down the class server, registry.unbind(name) to unbind the IHost stub, etc.
Tips:
addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { // call model to do clean up then call hide() and dispose() to kill this frame. } });This technique does not catch all shutdown scenarios, however.
java.lang.Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { // call method to do clean-up } });
© 2016 by Stephen Wong