import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; public class Squarer { private BlockingQueue in; private BlockingQueue out; Squarer(BlockingQueue request, BlockingQueue replies) { this.in = request; this.out = replies; } public void start() { new Thread(new Runnable() { public void run() { while(true) { try { int x = in.take(); int y = x*x; Thread.sleep(2000); System.out.println("OK, got it. Calculating.."); Thread.sleep(4000); out.put(new SquareResult(x,y)); } catch(InterruptedException e) { System.out.println("interrupted yo"); } } } }).start(); } }