A resolver task as a Runnable
A resolver task as a Runnable
Answer
class Resolver implements Runnable { private final String host; Resolver(String host) { this.host = host; } @Override public void run() { try { System.out.println(host + " " + InetAddress.getByName(host).getHostAddress()); } catch (UnknownHostException ex) { System.err.println(host + " unresolved"); } } }
The task holds only what it needs (one hostname, final) and swallows nothing silently — it reports the failure on stderr. Because it implements `Runnable` rather than extending `Thread`, the same object can later be submitted to an executor untouched.
Harold 4e ch3 §Running Threads