Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 17 design patterns Nowadays Id probably write that as a lambda like this Runnable command System out println Hello world Then assuming all the network plumbing has been set up there might be a method such as submit to send a command to the server remoteConnection submit myCommand To make the code clearer you could define Command as an interface that extends Runnable public interface Command extends Runnable Serializable empty Serializable is needed for some of the networking transports that might be used such as remote method invocation RMI and it costs nothing anyway Id simplify the code by instantiating the lambda inline as in the following remoteConnection submit System out println Hello world The code on the other end the server could implement this method in a simple fashion public void submit Command c c run Or the server could put the command into a batch queue run it in a thread pool see java util concurrent Executor or use any of several options Either way on the client side you dont know and shouldnt care Of course the Command interface could be changed to have arguments
You must have JavaScript enabled to view digital editions.