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(String name) 

Source Link

Document

Constructs a new thread group.

Usage

From source file:org.apache.axis2.transport.nhttp.Axis2AsyncWebProcessor.java

Axis2AsyncWebProcessor(int port) {
    this.port = port;
    // create thread pool of workers
    workerPool = new ThreadPoolExecutor(1, WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, TIME_UNIT,
            new LinkedBlockingQueue(),
            new DefaultThreadFactory(new ThreadGroup("HTTP Worker thread group"), "HTTPWorker"));
}

From source file:org.opencms.main.CmsThreadStore.java

/**
 * Hides the public constructor.<p>
 * //from  www  .  jav a2s .c  om
 * @param securityManager needed for scheduling "undercover-jobs" 
 *      that increase stability and fault tolerance
 */
protected CmsThreadStore(CmsSecurityManager securityManager) {

    super(new ThreadGroup("OpenCms Thread Store"), "OpenCms: Grim Reaper");
    setDaemon(true);
    // Hashtable is still the most efficient form of a synchronized HashMap
    m_threads = new Hashtable<CmsUUID, A_CmsReportThread>();
    m_alive = true;
    m_securityManager = securityManager;
    start();
}

From source file:com.nuvolect.deepdive.lucene.Index.java

public static JSONObject index(final String volumeId, final String searchPath, final boolean forceIndex) {

    if (m_interrupt[0]) {

        LogUtil.log(LogUtil.LogType.INDEX, "Index canceled post interrupt");

        m_interrupt[0] = false;//w w w.  ja  v  a2s  .  c  om
        return responseInterruptIndexing();
    }

    OmniFile cacheDir = IndexUtil.getCacheDir(volumeId, searchPath);
    boolean cacheDirCreated = false;
    try {
        cacheDirCreated = OmniUtil.forceMkdir(cacheDir);
    } catch (IOException e) {
        return responseFolderCreateError(searchPath);
    }

    final String luceneDirPath = cacheDir.getAbsolutePath();

    boolean cacheDirExists = !cacheDirCreated;
    boolean indexingOngoing = m_indexThread != null && m_indexThread.isAlive();
    boolean indexingRequired = !cacheDirExists || forceIndex;

    synchronized (m_lock) {

        if (indexingOngoing) {

            if (m_fileTreeActive)
                m_index_state = INDEX_STATE.filetree;
            else
                m_index_state = INDEX_STATE.indexing;
        } else {
            if (indexingRequired)
                m_index_state = INDEX_STATE.indexing;
            else
                m_index_state = INDEX_STATE.complete;
        }
    }

    if (indexingRequired || indexingOngoing) {

        if (indexingOngoing) {

            // Nothing to do, let the background process run. Monitor m_indexedDocs for progress.
        } else {

            synchronized (m_lock) {
                m_index_state = INDEX_STATE.filetree;
                m_totalDocs[0] = 0;
                m_indexedDocs[0] = 0;
                m_error[0] = "";
            }
            m_threadGroup = new ThreadGroup(INDEX_THREAD_GROUP);
            m_indexThread = new Thread(m_threadGroup, new Runnable() {
                @Override
                public void run() {

                    //                        Analyzer analyzer = new org.apache.lucene.analysis.core.WhitespaceAnalyzer();
                    //                        Analyzer analyzer = new org.apache.lucene.analysis.core.KeywordAnalyzer();
                    //                        Analyzer analyzer = new org.apache.lucene.analysis.standard.StandardAnalyzer();
                    Analyzer analyzer = new org.apache.lucene.analysis.core.SimpleAnalyzer();
                    IndexWriterConfig config = new IndexWriterConfig(analyzer);
                    IndexWriter iwriter = null;

                    try {
                        Directory m_directory = FSDirectory.open(Paths.get(luceneDirPath));
                        iwriter = new IndexWriter(m_directory, config);
                        iwriter.deleteAll();
                        iwriter.commit();
                    } catch (IOException e) {
                        LogUtil.logException(LogUtil.LogType.INDEX, e);
                        m_error[0] = "IndexWriter constructor exception";
                    }

                    synchronized (m_lock) {
                        m_fileTreeActive = true;
                        m_index_state = INDEX_STATE.filetree;
                    }
                    Collection<OmniFile> files = IndexUtil.getFilePaths(volumeId, searchPath);

                    synchronized (m_lock) {
                        m_index_state = INDEX_STATE.indexing;
                        m_fileTreeActive = false;
                        m_totalDocs[0] = files.size();
                        m_indexedDocs[0] = 0;
                    }

                    try {

                        for (OmniFile file : files) {

                            if (m_interrupt[0]) {
                                LogUtil.log(LogUtil.LogType.INDEX, "Iterator loop canceled");
                                break;
                            }

                            String path = file.getPath();

                            //                                LogUtil.log(LogUtil.LogType.INDEX, "indexing: " + path);// this is a bit excessive
                            iwriter.addDocument(makeDoc(volumeId, path));
                            synchronized (m_lock) {
                                ++m_indexedDocs[0];
                            }
                        }

                        iwriter.commit();
                        iwriter.close();
                        synchronized (m_lock) {
                            m_index_state = m_interrupt[0] ? INDEX_STATE.interrupted : INDEX_STATE.complete;
                            m_totalDocs[0] = m_indexedDocs[0];
                        }

                    } catch (Exception e) {
                        LogUtil.logException(LogUtil.LogType.INDEX, e);
                        m_error[0] = "IndexWriter addDocument exception";
                    }
                }
            }, INDEX_THREAD, STACK_SIZE);

            m_indexThread.setPriority(Thread.MAX_PRIORITY);
            m_indexThread.start();
        }
    } else {

        // Indexing is complete
        // Get number of documents indexed
        try {
            Directory directory = FSDirectory.open(Paths.get(luceneDirPath));
            DirectoryReader ireader = DirectoryReader.open(directory);
            synchronized (m_lock) {
                m_indexedDocs[0] = ireader.numDocs();
                m_totalDocs[0] = m_indexedDocs[0];
                m_index_state = INDEX_STATE.complete;
            }
            ireader.close();
            directory.close();
        } catch (IOException e) {
            LogUtil.logException(LogUtil.LogType.INDEX, e);
        }
    }

    JSONObject result = new JSONObject();
    try {
        synchronized (m_lock) {
            result.put("index_state", m_index_state.toString());
            result.put("error", m_error[0]);
            result.put("indexed_docs", m_indexedDocs[0]);
            result.put("total_docs", m_totalDocs[0]);
            //                result.put("full_path", cacheDir.getAbsolutePath());
            result.put("search_path", searchPath);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return result;
}

From source file:org.killbill.bus.DefaultPersistentBus.java

@Inject
public DefaultPersistentBus(@Named(QUEUE_NAME) final IDBI dbi, final Clock clock,
        final PersistentBusConfig config, final MetricRegistry metricRegistry,
        final DatabaseTransactionNotificationApi databaseTransactionNotificationApi) {
    super("Bus", Executors.newFixedThreadPool(config.getNbThreads(), new ThreadFactory() {
        @Override//from  ww w .j a  v  a  2 s.  com
        public Thread newThread(final Runnable r) {
            return new Thread(new ThreadGroup(EVENT_BUS_GROUP_NAME), r, config.getTableName() + "-th");
        }
    }), config.getNbThreads(), config);
    final PersistentBusSqlDao sqlDao = dbi.onDemand(PersistentBusSqlDao.class);
    this.clock = clock;
    final String dbBackedQId = "bus-" + config.getTableName();
    this.dao = new DBBackedQueue<BusEventModelDao>(clock, sqlDao, config, dbBackedQId, metricRegistry,
            databaseTransactionNotificationApi);
    this.eventBusDelegate = new EventBusDelegate("Killbill EventBus");
    this.dispatchTimer = metricRegistry.timer(MetricRegistry.name(DefaultPersistentBus.class, "dispatch"));
    this.isStarted = new AtomicBoolean(false);
}

From source file:com.jkoolcloud.tnt4j.streams.custom.dirStream.DefaultStreamingJob.java

/**
 * Initializes and starts configuration defined {@link TNTInputStream}s when job gets invoked by executor service.
 *//*from  w w w  .j a  va 2  s .  com*/
@Override
public void run() {
    // StreamsAgent.runFromAPI(streamCfgFile);

    // TODO: configuration from ZooKeeper

    try {
        StreamsConfigLoader cfg = new StreamsConfigLoader(streamCfgFile);
        Collection<TNTInputStream<?, ?>> streams = cfg.getStreams();

        if (CollectionUtils.isEmpty(streams)) {
            throw new IllegalStateException(StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME,
                    "StreamsAgent.no.activity.streams"));
        }

        ThreadGroup streamThreads = new ThreadGroup(DefaultStreamingJob.class.getName() + "Threads"); // NON-NLS
        StreamThread ft;

        DefaultStreamListener dsl = new DefaultStreamListener();

        for (TNTInputStream<?, ?> stream : streams) {
            stream.addStreamListener(dsl);

            stream.output().setProperty(OutputProperties.PROP_TNT4J_CONFIG_FILE, tnt4jCfgFilePath);

            ft = new StreamThread(streamThreads, stream,
                    String.format("%s:%s", stream.getClass().getSimpleName(), stream.getName())); // NON-NLS
            ft.start();
        }
    } catch (Exception e) {
        LOGGER.log(OpLevel.ERROR, String.valueOf(e.getLocalizedMessage()), e);
    }
}

From source file:org.apache.synapse.commons.executors.PriorityExecutor.java

/**
 * Initialize the executor by using the properties. Create the queues
 * and ThreadPool executor./*from   www.ja  va  2s .c  om*/
 */
public void init() {
    if (queue == null) {
        throw new IllegalStateException("Queue should be specified before initializing");
    }

    executor = new ThreadPoolExecutor(core, max, keepAlive, TimeUnit.SECONDS, queue, new NativeThreadFactory(
            new ThreadGroup("executor-group"), "priority-worker" + (name != null ? "-" + name : "")));

    initialzed = true;

    if (log.isDebugEnabled()) {
        log.debug("Started the thread pool executor with threads, " + "core = " + core + " max = " + max
                + ", keep-alive = " + keepAlive);
    }
}

From source file:org.apache.axis2.transport.base.threads.NativeWorkerPool.java

public NativeWorkerPool(int core, int max, int keepAlive, int queueLength, String threadGroupName,
        String threadGroupId, BlockingQueue<Runnable> queue,
        RejectedExecutionHandler rejectedExecutionHandler) {

    if (log.isDebugEnabled()) {
        log.debug("Using native util.concurrent package..");
    }/*from w  w  w .  j  av  a  2  s . c  om*/

    if (queue == null) {
        blockingQueue = (queueLength == -1 ? new LinkedBlockingQueue<Runnable>()
                : new LinkedBlockingQueue<Runnable>(queueLength));
    } else {
        blockingQueue = queue;
    }

    executor = new Axis2ThreadPoolExecutor(core, max, keepAlive, TimeUnit.SECONDS, blockingQueue,
            new NativeThreadFactory(new ThreadGroup(threadGroupName), threadGroupId), rejectedExecutionHandler);
}

From source file:org.siddhiesb.transport.passthru.workerpool.NativeWorkerPool.java

public NativeWorkerPool(int core, int max, int keepAlive, int queueLength, String threadGroupName,
        String threadGroupId, BlockingQueue<Runnable> queue,
        RejectedExecutionHandler rejectedExecutionHandler) {

    if (log.isDebugEnabled()) {
        log.debug("Using native util.concurrent package..");
    }/*from w w w  .j  a va 2 s . c o m*/

    if (queue == null) {
        blockingQueue = (queueLength == -1 ? new LinkedBlockingQueue<Runnable>()
                : new LinkedBlockingQueue<Runnable>(queueLength));
    } else {
        blockingQueue = queue;
    }

    executor = new PassThruThreadPoolExecutor(core, max, keepAlive, TimeUnit.SECONDS, blockingQueue,
            new NativeThreadFactory(new ThreadGroup(threadGroupName), threadGroupId), rejectedExecutionHandler);
}

From source file:org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetAsyncDiskService.java

/**
 * Create a AsyncDiskServices with a set of volumes (specified by their
 * root directories)./*from  w ww  .  j  av a  2s.com*/
 * <p/>
 * The AsyncDiskServices uses one ThreadPool per volume to do the async
 * disk operations.
 */
FsDatasetAsyncDiskService(DataNode datanode, FsDatasetImpl fsdatasetImpl) {
    this.datanode = datanode;
    this.fsdatasetImpl = fsdatasetImpl;
    this.threadGroup = new ThreadGroup(getClass().getSimpleName());
}

From source file:org.apache.fop.threading.FOPTestbed.java

/**
 * Starts the stress test.//from ww w. j a  v  a 2  s  .  c om
 */
public void doStressTest() {
    getLogger().info("Starting stress test...");
    long start = System.currentTimeMillis();
    this.counter = 0;

    //Initialize threads
    ThreadGroup workerGroup = new ThreadGroup("FOP workers");
    List threadList = new java.util.LinkedList();
    for (int ti = 0; ti < this.threads; ti++) {
        TaskRunner runner = new TaskRunner();
        ContainerUtil.enableLogging(runner, getLogger());
        Thread thread = new Thread(workerGroup, runner, "Worker- " + ti);
        threadList.add(thread);
    }

    //Start threads
    Iterator i = threadList.iterator();
    while (i.hasNext()) {
        ((Thread) i.next()).start();
    }

    //Wait for threads to end
    while (threadList.size() > 0) {
        Thread t = (Thread) threadList.get(0);
        if (!t.isAlive()) {
            threadList.remove(0);
            continue;
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException ie) {
            //ignore
        }
    }
    long duration = System.currentTimeMillis() - start;

    report(duration);
}