ZThread { public static Socket fork(ZContext ctx, IAttachedRunnable runnable, Object... args) { Socket pipe = ctx.createSocket(ZMQ.PAIR); if (pipe != null) { pipe.bind(String.format("inproc: } else { return null; } ZContext ccontext = ZContext.shadow(ctx); Socket cpipe = ccontext.createSocket(ZMQ.PAIR); if (cpipe == null) return null; cpipe.connect(String.format("inproc: Thread shim = new ShimThread(ccontext, runnable, args, cpipe); shim.start(); return pipe; }  static void start(IDetachedRunnable runnable, Object... args); static Socket fork(ZContext ctx, IAttachedRunnable runnable, Object... args);  }
@Test public void testFork() { ZContext ctx = new ZContext(); ZThread.IAttachedRunnable attached = new ZThread.IAttachedRunnable() { @Override public void run(Object[] args, ZContext ctx, Socket pipe) { ctx.createSocket(ZMQ.PUSH); pipe.recvStr(); pipe.send("pong"); } }; Socket pipe = ZThread.fork(ctx, attached); assert (pipe != null); pipe.send("ping"); String pong = pipe.recvStr(); Assert.assertEquals(pong, "pong"); ctx.destroy(); }