List of utility methods to do Thread Factory
ScheduledExecutorService | getScheduledExecutorService(final int maxNbThreads, final String name) Creates an ScheduledExecutorService object backed by a thread pool with a fixed number of threads.. return Executors.newScheduledThreadPool(maxNbThreads, new ThreadFactory() { public Thread newThread(Runnable r) { final Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setDaemon(true); thread.setName(name); return thread; }); ... |
ThreadFactory | getThreadFactory(String name) Based on the default thread factory return r -> { Thread t = Executors.defaultThreadFactory().newThread(r); t.setName(name + "-" + t.getName()); return t; }; |
ThreadFactory | getThreadFactory(String nameFormat, boolean daemon) Get a ThreadFactory suitable for use in the current environment. ThreadFactory threadFactory = MoreExecutors.platformThreadFactory(); return new ThreadFactoryBuilder().setThreadFactory(threadFactory).setDaemon(daemon) .setNameFormat(nameFormat).build(); |