Java Utililty Methods ThreadFactory

List of utility methods to do ThreadFactory

Description

The list of methods to do ThreadFactory are organized into topic(s).

Method

ThreadFactorycreateDaemonThreadFactory(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;
};
ThreadFactorycreateFactory(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());
...
ThreadFactorycreateNamedThreadFactory(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;
};
ThreadFactorycreateSimpleThreadFactory(final String name)
create Simple Thread Factory
return r -> {
    Thread t = new Thread(r);
    t.setName(name);
    t.setDaemon(true);
    return t;
};
ThreadFactorycreateThreadFactory(final String threadName, final int stackSize)
Returns a ThreadFactory that creates threads that run at minimum priority
return createThreadFactory(threadName, stackSize, Thread.MIN_PRIORITY);
ThreadFactoryCreateThreadFactory(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;
...
ThreadFactorycreateThreadFactory(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();
ThreadFactorycreateThreadFactory(String namePrefix)
create Thread Factory
return new ThreadFactoryBuilder().setDaemon(true).setNameFormat(namePrefix + "-%d").build();
ThreadFactorycreateThreadFactoryBuilder(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();
...
ThreadFactorygetThreadFactory(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;
};