Example usage for java.lang ThreadGroup ThreadGroup

List of usage examples for java.lang ThreadGroup ThreadGroup

Introduction

In this page you can find the example usage for java.lang ThreadGroup ThreadGroup.

Prototype

public ThreadGroup(ThreadGroup parent, String name) 

Source Link

Document

Creates a new thread group.

Usage

From source file:Main.java

public static ThreadGroup createThreadGroup(String name) {
    SecurityManager s = System.getSecurityManager();
    ThreadGroup parent = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
    return new ThreadGroup(parent, name);
}

From source file:org.onlab.util.GroupedThreadFactory.java

/**
 * Returns thread factory for producing threads associated with the specified
 * group name. The group name-space is hierarchical, based on slash-delimited
 * name segments, e.g. {@code onos/intent}.
 *
 * @param groupName group name/*from www .  j ava2 s  .  c om*/
 * @return thread factory
 */
public static GroupedThreadFactory groupedThreadFactory(String groupName) {
    GroupedThreadFactory factory = FACTORIES.get(groupName);
    if (factory != null) {
        return factory;
    }

    // Find the parent group or root the group hierarchy under default group.
    int i = groupName.lastIndexOf(DELIMITER);
    if (i > 0) {
        String name = groupName.substring(0, i);
        ThreadGroup parentGroup = groupedThreadFactory(name).threadGroup();
        factory = new GroupedThreadFactory(new ThreadGroup(parentGroup, groupName));
    } else {
        factory = new GroupedThreadFactory(new ThreadGroup(groupName));
    }

    return ConcurrentUtils.putIfAbsent(FACTORIES, groupName, factory);
}

From source file:org.opendaylight.atrium.util.AtriumGroupedThreadFactory.java

/**
 * Returns thread factory for producing threads associated with the specified
 * group name. The group name-space is hierarchical, based on slash-delimited
 * name segments, /*w w  w . ja  v a 2s.c  o m*/
 *
 * @param groupName group name
 * @return thread factory
 */
public static AtriumGroupedThreadFactory groupedThreadFactory(String groupName) {
    AtriumGroupedThreadFactory factory = FACTORIES.get(groupName);
    if (factory != null) {
        return factory;
    }

    // Find the parent group or root the group hierarchy under default group.
    int i = groupName.lastIndexOf(DELIMITER);
    if (i > 0) {
        String name = groupName.substring(0, i);
        ThreadGroup parentGroup = groupedThreadFactory(name).threadGroup();
        factory = new AtriumGroupedThreadFactory(new ThreadGroup(parentGroup, groupName));
    } else {
        factory = new AtriumGroupedThreadFactory(new ThreadGroup(groupName));
    }

    return ConcurrentUtils.putIfAbsent(FACTORIES, groupName, factory);
}

From source file:org.quartz.simpl.SimpleThreadPool.java

public void initialize() throws SchedulerConfigException {

    if (count <= 0) {
        throw new SchedulerConfigException("Thread count must be > 0");
    }//from   w  w w .jav  a2 s  . c  o m
    if (prio <= 0 || prio > 9) {
        throw new SchedulerConfigException("Thread priority must be > 0 and <= 9");
    }

    if (isThreadsInheritGroupOfInitializingThread()) {
        threadGroup = Thread.currentThread().getThreadGroup();
    } else {
        // follow the threadGroup tree to the root thread group.
        threadGroup = Thread.currentThread().getThreadGroup();
        ThreadGroup parent = threadGroup;
        while (!parent.getName().equals("main")) {
            threadGroup = parent;
            parent = threadGroup.getParent();
        }
        threadGroup = new ThreadGroup(parent, "SimpleThreadPool");
        if (isMakeThreadsDaemons()) {
            threadGroup.setDaemon(true);
        }
    }

    if (isThreadsInheritContextClassLoaderOfInitializingThread()) {
        getLog().info(
                "Job execution threads will use class loader of thread: " + Thread.currentThread().getName());
    }

    // create the worker threads and start them
    Iterator workerThreads = createWorkerThreads(count).iterator();
    while (workerThreads.hasNext()) {
        WorkerThread wt = (WorkerThread) workerThreads.next();
        wt.start();
        availWorkers.add(wt);
    }
}

From source file:de.micromata.genome.chronos.spi.SchedulerImpl.java

/**
 * Instanziiert den Thread-Pool./* w  w  w  .j a  va2s .c  om*/
 *
 * @param threadPoolSize the thread pool size
 * @param name the name
 */
private void initThreadPool(final int threadPoolSize, final String name) {
    queue = new LinkedBlockingQueue<Runnable>();
    this.threadPoolSize = threadPoolSize;

    int i = threadPoolSize;
    if (threadPoolSize == 0) {
        i = 1;
        GLog.warn(GenomeLogCategory.Scheduler, "ThreadPoolSize is given with 0: " + name);
    }
    // es muss mind. ein Thread sein
    executor = new SchedulerThreadPoolExecutor(threadPoolSize, i, 1, TimeUnit.SECONDS, queue, this);
    SchedulerThreadFactory tfactory = new SchedulerThreadFactory();
    String appId = ChronosServiceManager.get().getSchedulerDAO().getShortApplicationName();
    String threadGroupName = "JCWTG[" + appId + "]: " + dispatcher.getDispatcherName() + "; " + name;
    ThreadGroup threadGroup = new ThreadGroup(dispatcher.getCreateDispatcherThreadGroup(), threadGroupName);
    tfactory.setThreadGroup(threadGroup);
    tfactory.setThreadNamePrefix("JCWT[" + appId + "]: " + dispatcher.getDispatcherName() + "; " + name);
    executor.setThreadFactory(tfactory);
}

From source file:org.archive.modules.postprocessor.KafkaCrawlLogFeed.java

protected KafkaProducer<String, byte[]> kafkaProducer() {
    if (kafkaProducer == null) {
        synchronized (this) {
            if (kafkaProducer == null) {
                final Properties props = new Properties();
                props.put("bootstrap.servers", getBrokerList());
                props.put("acks", "1");
                props.put("producer.type", "async");
                props.put("key.serializer", StringSerializer.class.getName());
                props.put("value.serializer", ByteArraySerializer.class.getName());

                /*//from  w w w  .java2 s.  c  om
                 * XXX This mess here exists so that the kafka producer
                 * thread is in a thread group that is not the ToePool,
                 * so that it doesn't get interrupted at the end of the
                 * crawl in ToePool.cleanup(). 
                 */
                kafkaProducerThreads = new ThreadGroup(Thread.currentThread().getThreadGroup().getParent(),
                        "KafkaProducerThreads");
                ThreadFactory threadFactory = new ThreadFactory() {
                    public Thread newThread(Runnable r) {
                        return new Thread(kafkaProducerThreads, r);
                    }
                };
                Callable<KafkaProducer<String, byte[]>> task = new Callable<KafkaProducer<String, byte[]>>() {
                    public KafkaProducer<String, byte[]> call() throws InterruptedException {
                        return new KafkaProducer<String, byte[]>(props);
                    }
                };
                ExecutorService executorService = Executors.newFixedThreadPool(1, threadFactory);
                Future<KafkaProducer<String, byte[]>> future = executorService.submit(task);
                try {
                    kafkaProducer = future.get();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (ExecutionException e) {
                    throw new RuntimeException(e);
                } finally {
                    executorService.shutdown();
                }
            }
        }
    }
    return kafkaProducer;
}

From source file:org.opencms.scheduler.CmsSchedulerThreadPool.java

/**
 * @see org.quartz.spi.ThreadPool#initialize()
 *///from  w w w.  ja  v a  2 s. c  o  m
public void initialize() throws SchedulerConfigException {

    if ((m_maxThreadCount <= 0) || (m_maxThreadCount > 200)) {
        throw new SchedulerConfigException(
                Messages.get().getBundle().key(Messages.ERR_MAX_THREAD_COUNT_BOUNDS_0));
    }
    if ((m_initialThreadCount < 0) || (m_initialThreadCount > m_maxThreadCount)) {
        throw new SchedulerConfigException(
                Messages.get().getBundle().key(Messages.ERR_INIT_THREAD_COUNT_BOUNDS_0));
    }
    if ((m_threadPriority <= 0) || (m_threadPriority > 9)) {
        throw new SchedulerConfigException(
                Messages.get().getBundle().key(Messages.ERR_SCHEDULER_PRIORITY_BOUNDS_0));
    }

    if (m_inheritGroup) {
        m_threadGroup = Thread.currentThread().getThreadGroup();
    } else {
        // follow the threadGroup tree to the root thread group
        m_threadGroup = Thread.currentThread().getThreadGroup();
        ThreadGroup parent = m_threadGroup;
        while (!parent.getName().equals("main")) {
            m_threadGroup = parent;
            parent = m_threadGroup.getParent();
        }
        m_threadGroup = new ThreadGroup(parent, this.getClass().getName());
    }

    if (m_inheritLoader) {
        LOG.debug(Messages.get().getBundle().key(Messages.LOG_USING_THREAD_CLASSLOADER_1,
                Thread.currentThread().getName()));
    }

    // create the worker threads and start them
    m_workers = new CmsSchedulerThread[m_maxThreadCount];
    for (int i = 0; i < m_initialThreadCount; ++i) {
        growThreadPool();
    }
}

From source file:com.icbc.Scheduler.ThreadManager.SchedulerThreadPool.java

public void initialize() {

    runnableQueue = new SchedulerThreadQueue(ThreadQueueSize);
    if (count <= 0) {
        System.err.println("Thread count must be > 0");
    }/*from   w ww  .j a  v a 2s. com*/
    if (prio <= 0 || prio > 9) {
        System.err.println("Thread priority must be > 0 and <= 9");
    }

    if (isThreadsInheritGroupOfInitializingThread()) {
        threadGroup = Thread.currentThread().getThreadGroup();
    } else {
        // follow the threadGroup tree to the root thread group.
        threadGroup = Thread.currentThread().getThreadGroup();
        ThreadGroup parent = threadGroup;
        while (!parent.getName().equals("main")) {
            threadGroup = parent;
            parent = threadGroup.getParent();
        }
        threadGroup = new ThreadGroup(parent, "SchedulerThreadPool");
    }

    if (isThreadsInheritContextClassLoaderOfInitializingThread()) {
        getLog().info(
                "Job execution threads will use class loader of thread: " + Thread.currentThread().getName());
    }

    // create the worker threads and start them
    workers = createWorkerThreads(count);

    for (int i = 0; i < count; ++i) {
        if (isThreadsInheritContextClassLoaderOfInitializingThread()) {
            workers[i].setContextClassLoader(Thread.currentThread().getContextClassLoader());
        }
    }

    LogProvider.outLog("INFO", threadPoolName + " initialize successfully!",
            GlobalDefine.LOG_LOGGER_DYNAMIC_FILE, "WorkerThread_run");
}

From source file:CachedThread.java

/**
 * Create a thread cache, after creating a new thread group.
 * @param parent The parent of the thread group to create.
 * @param name The name of the thread group.
 *//*  w ww .ja  va2s.c o m*/

public ThreadCache(ThreadGroup parent, String name) {
    this(new ThreadGroup(parent, name));
}

From source file:org.jspresso.framework.application.backend.AbstractBackendController.java

private synchronized ThreadGroup getControllerAsyncActionsThreadGroup() {
    if (controllerAsyncActionsThreadGroup == null || controllerAsyncActionsThreadGroup.isDestroyed()) {
        controllerAsyncActionsThreadGroup = new ThreadGroup(asyncActionsThreadGroup, toString());
    }//w  w  w .j  a  v a 2 s  . c o m
    return controllerAsyncActionsThreadGroup;
}