private static ThreadFactory newThreadFactory ( final String id ) { return new ThreadFactory ( ) { private final AtomicInteger next = new AtomicInteger ( ) ; @ Override public Thread newThread ( Runnable r ) { final String name = "spectator-" + id + "-" + next . getAndIncrement ( ) ; final Thread t = new Thread ( r , name ) ; t . setDaemon ( true ) ; return t ; } } ; }
Create a thread factory using thread names based on the id . All threads will be configured as daemon threads .