List of utility methods to do ThreadFactory
ThreadFactory | createDaemonThreadFactory(final int threadPriority, final ThreadGroup group, final ClassLoader contextClassLoader) Creates a new instance of the thread factory with given thread instantiation parameters. return r -> { final Thread t = new Thread(group, r); t.setDaemon(true); t.setPriority(threadPriority); t.setContextClassLoader(contextClassLoader); return t; }; |
ThreadFactory | createFactory(final String threadName) create Factory return new ThreadFactory() { int sequence; public Thread newThread(Runnable r) { sequence += 1; StringBuilder sb = new StringBuilder(); sb.append('[').append(Thread.currentThread().getThreadGroup().getName()).append("] "); sb.append(threadName).append(" - ").append(sequence); return new Thread(r, sb.toString()); ... |
ThreadFactory | createNamedThreadFactory(final String threadName) Creates a thread factory which creates named daemon threads. return r -> { Thread thread = new Thread(r, threadName); thread.setDaemon(true); return thread; }; |
ThreadFactory | createSimpleThreadFactory(final String name) create Simple Thread Factory return r -> { Thread t = new Thread(r); t.setName(name); t.setDaemon(true); return t; }; |
ThreadFactory | createThreadFactory(final String threadName, final int stackSize) Returns a ThreadFactory that creates threads that run at minimum priority
return createThreadFactory(threadName, stackSize, Thread.MIN_PRIORITY);
|
ThreadFactory | CreateThreadFactory(final ThreadGroup tg, final String threadName) Create Thread Factory final ThreadFactory threadFactory = new ThreadFactory() { public Thread newThread(Runnable command) { Thread thread = new Thread(tg, command, threadName); thread.setDaemon(true); return thread; }; return threadFactory; ... |
ThreadFactory | createThreadFactory(String nameFormat, Thread.UncaughtExceptionHandler exceptionHandler) Creates new thread factory with specified thread name format. ThreadFactoryBuilder builder = new ThreadFactoryBuilder().setNameFormat(nameFormat).setDaemon(true); if (exceptionHandler != null) { builder.setUncaughtExceptionHandler(exceptionHandler); return builder.build(); |
ThreadFactory | createThreadFactory(String namePrefix) create Thread Factory return new ThreadFactoryBuilder().setDaemon(true).setNameFormat(namePrefix + "-%d").build(); |
ThreadFactory | createThreadFactoryBuilder(final String baseName, final String componentName) Creates a thread factory builder. StringBuilder buf = new StringBuilder("ACP:"); if (!Strings.isNullOrEmpty(baseName)) { buf.append(baseName).append(":").append(componentName); } else { buf.append(componentName); buf.append("-Thread-%d"); return new ThreadFactoryBuilder().setNameFormat(buf.toString()).build(); ... |
ThreadFactory | getThreadFactory(final String THREAD_NAME, final boolean IS_DAEMON) get Thread Factory return runnable -> { Thread thread = new Thread(runnable, THREAD_NAME); thread.setDaemon(IS_DAEMON); return thread; }; |