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:Server.java

/**
 * This is the Server() constructor. It must be passed a stream to send log
 * output to (may be null), and the limit on the number of concurrent
 * connections./* w ww.j  a v  a  2  s . c  o  m*/
 */
public Server(OutputStream logStream, int maxConnections) {
    setLogStream(logStream);
    log("Starting server");
    threadGroup = new ThreadGroup(Server.class.getName());
    this.maxConnections = maxConnections;
    services = new HashMap();
    connections = new HashSet(maxConnections);
}

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

@Override
public ThreadGroup getCreateDispatcherThreadGroup() {
    if (dispatcherThreadGroup != null) {
        return dispatcherThreadGroup;
    }// w  w  w .ja va2 s.  c o m
    dispatcherThreadGroup = new ThreadGroup("JCDTG[" + getShortApplicationName() + "]: " + getDispatcherName());
    return dispatcherThreadGroup;
}

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

public NativeWorkerPool(int core, int max, int keepAlive, int queueLength, int waterMark,
        String threadGroupName, String threadGroupId, WaterMarkQueue<Runnable> queue) {

    if (log.isDebugEnabled()) {
        log.debug("Using native util.concurrent package..");
    }/*from  www . j a  v  a2s.  c  o  m*/

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

    executor = new WaterMarkExecutor(core, max, keepAlive, TimeUnit.SECONDS,
            (WaterMarkQueue<Runnable>) blockingQueue,
            new NativeThreadFactory(new ThreadGroup(threadGroupName), threadGroupId));
}

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

public NativeWorkerPool(int core, int max, int keepAlive, int queueLength, int waterMark,
        String threadGroupName, String threadGroupId,
        org.siddhiesb.transport.passthru.workerpool.WaterMarkQueue<Runnable> queue) {

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

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

    executor = new WaterMarkExecutor(core, max, keepAlive, TimeUnit.SECONDS,
            (org.siddhiesb.transport.passthru.workerpool.WaterMarkQueue<Runnable>) blockingQueue,
            new NativeThreadFactory(new ThreadGroup(threadGroupName), threadGroupId));
}

From source file:org.alfresco.bm.server.EventController.java

/**
 * Construct the controller//  w  w  w.j  a va 2 s. c om
 * 
 * @param driverId          the ID of the driver controlling the events
 * @param testRunFqn        the fully qualified name of the test run
 * @param testDAO           the test DAO for accessing low level data
 * @param testRunId         the ID of the test run being controlled
 * @param eventService      the source of events that will be pushed for execution
 * @param eventProducers    the registry of producers of events
 * @param eventProcessors   the registry of processors for events
 * @param resultService     the service used to store and retrieve event results
 * @param sessionService    the service to carry session IDs between events
 * @param logService        the service to record log messages for the end user
 * @param threadCount       the number of threads available to the processor
 */
public EventController(String driverId, String testRunFqn, EventService eventService,
        EventProducerRegistry eventProducers, EventProcessorRegistry eventProcessors,
        ResultService resultService, SessionService sessionService, TestRunLogService logService,
        int threadCount) {
    thread = new Thread(new ThreadGroup(testRunFqn), this, testRunFqn + "-Controller");
    thread.setDaemon(false); // Requires explicit shutdown

    this.driverId = driverId;
    this.testRunFqn = testRunFqn;
    this.eventService = eventService;
    this.eventProducers = eventProducers;
    this.eventProcessors = eventProcessors;
    this.resultService = resultService;
    this.sessionService = sessionService;
    this.logService = logService;
    this.threadCount = threadCount;
    // Configure threads
    CustomizableThreadFactory threadFactory = new CustomizableThreadFactory(testRunFqn + "-");
    threadFactory.setThreadGroup(thread.getThreadGroup());
    threadFactory.setDaemon(true);
    // Configure work queue
    SynchronousQueue<Runnable> queue = new SynchronousQueue<Runnable>(true);
    // Configure executor
    RejectedExecutionHandler abortPolicy = new ThreadPoolExecutor.CallerRunsPolicy();
    executor = new ThreadPoolExecutor(threadCount, threadCount, 60, TimeUnit.SECONDS, queue, threadFactory,
            abortPolicy);

    setRunning(true);
}

From source file:org.apache.xmlrpc.WebServer.java

/**
 * Creates a web server at the specified port number and IP
 * address./*from w ww  .j ava  2 s . c o m*/
 */
public WebServer(int port, InetAddress addr, XmlRpcServer xmlrpc) {
    this.address = addr;
    this.port = port;
    this.xmlrpc = xmlrpc;
    accept = new Vector();
    deny = new Vector();
    threadpool = new Stack();
    runners = new ThreadGroup("XML-RPC Runner");
}

From source file:it.cnr.icar.eric.server.query.federation.FederatedQueryProcessor.java

/**
 * Submits an AdhocQueryRequest to all Registries thare are members of specified federation.
 *
 * @param user/* w  w  w .j  a  va2  s. c o m*/
 * @param adhocQueryRequest the request sent to every registry ias a parrallel distrubuted query.
 */
public AdhocQueryResponse submitAdhocQuery(final ServerRequestContext context) throws RegistryException {

    this.adhocQueryRequest = (AdhocQueryRequest) context.getCurrentRegistryRequest();
    try {
        //Reset federated flag before doing federated query to avoid infinite loop
        adhocQueryRequest.setFederated(false);

        //Reset federation flag before doing federated query to avoid potential 
        //for implementations to interpret non-null values as implying federated query
        adhocQueryRequest.setFederation(null);

        // Create a barrier for all worker threads
        log.trace("Dispatching federated query to " + members.size() + " member registries.");
        CyclicBarrier barrier = new CyclicBarrier(members.size(), new Runnable() {
            public void run() {
                retrieveResults(context);
            }
        });

        ThreadGroup threadGroup = new ThreadGroup("federatedQuery");
        // Send a request to all destinations
        Iterator<RegistryType> i = members.iterator();
        while (i.hasNext()) {
            RegistryType registry = i.next();
            FederatedQueryWorker worker = new FederatedQueryWorker(barrier, registry, TIMEOUT_CONSTANT,
                    context.getUser(), adhocQueryRequest);
            workers.add(worker);
            //Thread thread = new Thread(threadGroup, worker);
            Thread thread = new Thread(threadGroup, worker, "Federated_Query_" + registry.getId());
            threads.add(thread);
            log.trace("Dispatching query to registry with id: " + registry.getId() + " name: "
                    + bu.getInternationalStringAsString(registry.getName()));
            thread.start();
        }

        Iterator<Thread> i1 = threads.iterator();
        while (i1.hasNext()) {
            Thread thread = i1.next();
            // Wait until all threads have finished.
            // CAVEAT: The timeouts will add up, max. waiting time is (number of threads) * (timeout)
            try {
                thread.join(TIMEOUT_CONSTANT);
            } catch (InterruptedException e) {
                //TODO: Try to kill the thread somehow
            }
        }
    } catch (JAXRException e) {
        //This exception is thrown potentially (unlikely) by bu.getInternationalStringAsString
        throw new RegistryException(e);
    }

    return getUnifiedResponse();
}

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

public NativeWorkerPool(int core, int max, int keepAlive, int queueLength, int waterMark,
        String threadGroupName, String threadGroupId, RejectedExecutionHandler rejectedExecutionHandler) {

    if (log.isDebugEnabled()) {
        log.debug("Using native util.concurrent package..");
    }/* www. j a va2  s  . co m*/

    blockingQueue = (queueLength == -1 ? new DefaultWaterMarkQueue<Runnable>(waterMark)
            : new DefaultWaterMarkQueue<Runnable>(waterMark, queueLength));

    executor = new WaterMarkExecutor(core, max, keepAlive, TimeUnit.SECONDS,
            (WaterMarkQueue<Runnable>) blockingQueue,
            new NativeThreadFactory(new ThreadGroup(threadGroupName), threadGroupId), rejectedExecutionHandler);
}

From source file:com.mellanox.r4h.DataXceiverServer.java

DataXceiverServer(DataNodeBridge dnBridge) throws URISyntaxException {
    super(new URI(String.format("rdma://%s", dnBridge.getDN().getDisplayName())), dnBridge.numOfMsgsToBind,
            dnBridge.msgInSize, dnBridge.msgOutSize, dnBridge.numSessionsLimit, 0,
            dnBridge.dynamicMsgAllocationAmount, !dnBridge.isForwardEnable);
    LOG.debug("After EventQueueHandler creation");

    this.dnBridge = dnBridge; // TODO: remove debug DNexpoable and rename top DataNodeBridge
    this.threadGroup = new ThreadGroup("R4H Datanode Threads");
    LOG.info("Creating DataXceiverServer - uri=" + uri);
    DataXceiverServer.DXSCallbacks dxsCbs = this.new DXSCallbacks();

    LOG.trace("writePacketSize=" + dnBridge.getWritePacketSize());

    URI workerUri = new URI(String.format("rdma://%s:0", this.uri.getHost()));

    this.spPool = new LinkedList<ServerPortalWorker>();

    isForwardEnable = dnBridge.isForwardEnable;

    if (isForwardEnable) {
        this.sp = new ServerPortal(eqh, uri, dxsCbs, new WorkerCache.WorkerProvider() {
            @Override//from   ww  w .j  a  va  2 s  . c om
            public Worker getWorker() {
                return getNextFreePortalWorker();
            }
        });

        LOG.info("Using forward model");
        int spwAmount = dnBridge.spwAmount;

        LOG.info(String.format("Starting ahead %d server portal worker with sessions limit of %d sessions each",
                spwAmount, dnBridge.numSessionsLimit));
        for (int i = 1; i <= spwAmount; i++) {
            ServerPortalWorker spw = new ServerPortalWorker(workerUri, dnBridge.numOfMsgsToBind / spwAmount,
                    dnBridge.msgInSize, dnBridge.msgOutSize, dnBridge.numSessionsLimit, i,
                    dnBridge.dynamicMsgAllocationAmount);
            spw.start();
            spPool.add(spw);
            LOG.info("Started new server portal worker thread: " + spw);
        }
    } else {
        this.sp = new ServerPortal(eqh, uri, dxsCbs);

        LOG.info("Using accept model");
        LOG.info("Started a new worker thread: " + super.toString());
    }

    auxThreadFactory = new ThreadFactoryBuilder().setNameFormat("r4h-auxillary-thread-%d").build();
    ThreadFactory ioThreadFactory = new ThreadFactoryBuilder().setNameFormat("r4h-io-thread-%d").build();

    LOG.info(String.format("Allocating ahead %d IO executors", dnBridge.numOfioExecutors));
    this.ioExecutorPool = new LinkedList<R4HExecutor>();
    for (int i = 0; i < dnBridge.numOfioExecutors; i++) {
        ioExecutorPool.add(new R4HExecutor(ioThreadFactory));
    }

    LOG.info(String.format("Allocating ahead %d Auxillary executors", dnBridge.numOfAuxExecutors));
    this.auxExecutorPool = new ConcurrentLinkedQueue<R4HExecutor>();
    for (int i = 0; i < dnBridge.numOfAuxExecutors; i++) {
        auxExecutorPool.add(new R4HExecutor(auxThreadFactory));
    }

    LOG.trace(this.toString());
}