Example usage for java.util.concurrent ThreadFactory ThreadFactory

List of usage examples for java.util.concurrent ThreadFactory ThreadFactory

Introduction

In this page you can find the example usage for java.util.concurrent ThreadFactory ThreadFactory.

Prototype

ThreadFactory

Source Link

Usage

From source file:Main.java

public static ThreadFactory newGenericThreadFactory(final String processName, final int threads,
        final boolean isDaemon) {
    return new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);

        @Override/*from   w  w w .  j a  va 2  s .c o  m*/
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r,
                    String.format("%s_%d_%d", processName, threads, this.threadIndex.incrementAndGet()));
            thread.setDaemon(isDaemon);
            return thread;
        }
    };
}

From source file:org.jboss.forge.addon.resource.monitor.FileMonitor.java

public FileMonitor() {
    alterationMonitor = new FileAlterationMonitor(CHECK_INTERVAL);
    alterationMonitor.setThreadFactory(new ThreadFactory() {
        @Override/*from  w  ww .  jav  a2  s.  c o m*/
        public Thread newThread(Runnable r) {
            Thread resourceMonitorThread = new Thread(r, "Resource File Monitor");
            resourceMonitorThread.setDaemon(true);
            resourceMonitorThread.setContextClassLoader(null);
            return resourceMonitorThread;
        }
    });
}

From source file:org.nuxeo.ecm.automation.client.jaxrs.spi.AsyncAutomationClient.java

/**
 * Instantiates a new asynchronous automation client with the default timeout for the wait of the asynchronous
 * thread pool termination: 2 seconds./* w  ww  . j a  va2  s.co  m*/
 */
public AsyncAutomationClient(String url) {
    this(url, Executors.newCachedThreadPool(new ThreadFactory() {
        public Thread newThread(Runnable r) {
            return new Thread("AutomationAsyncExecutor");
        }
    }));
}

From source file:com.clustercontrol.monitor.run.util.ParallelExecution.java

/**
 * /*  ww w .ja va  2 s.c o  m*/
 */
private ParallelExecution() {
    log.debug("init()");

    int m_maxThreadPool = HinemosPropertyUtil
            .getHinemosPropertyNum("monitor.common.thread.pool", Long.valueOf(10)).intValue();
    log.info("monitor.common.thread.pool: " + m_maxThreadPool);

    es = new MonitoredThreadPoolExecutor(m_maxThreadPool, m_maxThreadPool, 0L, TimeUnit.MICROSECONDS,
            new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
                private volatile int _count = 0;

                @Override
                public Thread newThread(Runnable r) {
                    return new Thread(r, "MonitorWorker-" + _count++);
                }
            }, new ThreadPoolExecutor.AbortPolicy());

    log.debug("ParallelExecution() ExecutorService is " + es.getClass().getCanonicalName());
    log.debug("ParallelExecution() securityManager is " + System.getSecurityManager());
}

From source file:com.hellblazer.jackal.configuration.ThreadConfig.java

@Bean(name = "agentDispatchers")
@Lazy/* ww  w  .  ja  va 2s  . c  o  m*/
@Autowired
public ExecutorService agentDispatchers(Identity partitionIdentity) {
    final int id = partitionIdentity.id;
    return Executors.newCachedThreadPool(new ThreadFactory() {
        int count = 0;

        @Override
        public Thread newThread(Runnable target) {
            Thread t = new Thread(target, String.format("Agent Dispatcher[%s] for node[%s]", count++, id));
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    log.error(String.format("Exception on %s", t), e);
                }
            });
            return t;
        }
    });
}

From source file:io.gravitee.gateway.report.impl.lmax.LmaxReporterService.java

@Override
public void afterPropertiesSet() throws Exception {
    ReportableEventFactory factory = new ReportableEventFactory();
    int bufferSize = environment.getProperty("reporters.system.buffersize", int.class, 4096);

    disruptor = new Disruptor<>(factory, bufferSize, new ThreadFactory() {
        private int counter = 0;
        private static final String THREAD_PREFIX = "reporter-disruptor";

        @Override// www.j  a va  2 s.c o m
        public Thread newThread(Runnable r) {
            return new Thread(r, THREAD_PREFIX + '-' + counter++);
        }
    }, ProducerType.MULTI, new BlockingWaitStrategy());
}

From source file:org.hyperic.util.thread.ThreadWatchdog.java

public ThreadWatchdog() {
    _tFact = new ThreadFactory() {
        public Thread newThread(Runnable r) {
            return new Thread(r, "ThreadWatchdog");
        }//from w w w .  j a  v  a2s .  co  m
    };
}

From source file:me.bulat.jivr.webmin.consul.service.ConsulServiceImpl.java

@Autowired
public ConsulServiceImpl(final ConsulManager consul) {
    this.consul = consul;
    this.healthCheck = Executors.newScheduledThreadPool(1, new ThreadFactory() {
        @Override// ww w .j  a  va 2 s. c  o  m
        public Thread newThread(Runnable r) {
            return new Thread(r, "JIVR-WEB-HEALTH-SERVICE");
        }
    });
}

From source file:com.reactivetechnologies.platform.rest.client.AsyncClientHandlerFactoryBean.java

@PostConstruct
private void init() {
    threads = Executors.newCachedThreadPool(new ThreadFactory() {
        private int n = 0;

        @Override//from w  ww.j a  v a  2s. c om
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, "REST-AsyncClientHandler-" + (n++));
            t.setDaemon(true);
            return t;
        }
    });
}

From source file:org.springframework.cloud.commons.util.InetUtils.java

public InetUtils(final InetUtilsProperties properties) {
    this.properties = properties;
    this.executorService = Executors.newSingleThreadExecutor(new ThreadFactory() {
        @Override/*from w  ww  .  ja  va2s. c o  m*/
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r);
            thread.setName(InetUtilsProperties.PREFIX);
            thread.setDaemon(true);
            return thread;
        }
    });
}