Example usage for java.util.concurrent Executors defaultThreadFactory

List of usage examples for java.util.concurrent Executors defaultThreadFactory

Introduction

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

Prototype

public static ThreadFactory defaultThreadFactory() 

Source Link

Document

Returns a default thread factory used to create new threads.

Usage

From source file:com.alibaba.napoli.gecko.service.timer.HashedWheelTimer.java

/**
 * Creates a new timer with the default thread factory (
 * {@link Executors#defaultThreadFactory()}).
 * /*from  ww  w  . j  ava 2  s  . c o m*/
 * @param tickDuration
 *            the duration between tick
 * @param unit
 *            the time unit of the {@code tickDuration}
 * @param ticksPerWheel
 *            the size of the wheel
 */
public HashedWheelTimer(final long tickDuration, final TimeUnit unit, final int ticksPerWheel,
        final int maxTimerCapacity) {
    this(Executors.defaultThreadFactory(), tickDuration, unit, ticksPerWheel, maxTimerCapacity);
}

From source file:org.apache.nifi.registry.bootstrap.RunNiFiRegistry.java

public RunNiFiRegistry(final File bootstrapConfigFile, final boolean verbose) throws IOException {
    this.bootstrapConfigFile = bootstrapConfigFile;

    loggingExecutor = Executors.newFixedThreadPool(2, new ThreadFactory() {
        @Override/*ww  w .  jav a2  s  .com*/
        public Thread newThread(final Runnable runnable) {
            final Thread t = Executors.defaultThreadFactory().newThread(runnable);
            t.setDaemon(true);
            t.setName("NiFi logging handler");
            return t;
        }
    });
}

From source file:tv.arte.resteventapi.core.scheduling.RestEventScheduledThreadPoolExecutorScheduler.java

/**
 * @see ScheduledThreadPoolExecutor#ScheduledThreadPoolExecutor(int)
 *///from ww w .j  a va  2  s.  co m
public RestEventScheduledThreadPoolExecutorScheduler(int corePoolSize) {
    this(corePoolSize, Executors.defaultThreadFactory(), new ThreadPoolExecutor.DiscardPolicy(), null, null);
}

From source file:eagle.jobrunning.crawler.RunningJobCrawlerImpl.java

private void startJobConfigProcessThread() {
    int configThreadCount = DEFAULT_CONFIG_THREAD_COUNT;
    LOG.info("Job Config crawler main thread started, pool size: " + DEFAULT_CONFIG_THREAD_COUNT);

    ThreadFactory factory = new ThreadFactory() {
        private final AtomicInteger count = new AtomicInteger(0);

        public Thread newThread(Runnable runnable) {
            count.incrementAndGet();//from   w  w w.j ava2 s  .c  o  m
            Thread thread = Executors.defaultThreadFactory().newThread(runnable);
            thread.setName("config-crawler-workthread-" + count.get());
            return thread;
        }
    };

    ThreadPoolExecutor pool = new ThreadPoolExecutor(configThreadCount, configThreadCount, 0L,
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory);

    while (true) {
        JobContext context;
        try {
            context = queueOfConfig.take();
            LOG.info("queueOfConfig size: " + queueOfConfig.size());
            Runnable configCrawlerThread = new ConfigWorkTask(new JobContext(context), fetcher, callback, this);
            pool.execute(configCrawlerThread);
        } catch (InterruptedException e) {
            LOG.warn("Got an InterruptedException: " + e.getMessage());
        } catch (RejectedExecutionException e2) {
            LOG.warn("Got RejectedExecutionException: " + e2.getMessage());
        } catch (Throwable t) {
            LOG.warn("Got an throwable t, " + t.getMessage());
        }
    }
}

From source file:edu.uga.cs.fluxbuster.clustering.ClusterGenerator.java

/**
 * Compute a distance matrix from a list of candidate flux domains with
 * a maximum number of calculation threads.
 *
 * @param cfds the list of candidate flux domains
 * @param maxnumthreads the thread ceiling
 * @return the vector of values in the distance matrix in row major
 *       order//from ww w .  java2  s  . c  o  m
 */
private Vector<Float> computeDistanceMatrixMultiThreaded(List<CandidateFluxDomain> cfds, int maxnumthreads) {
    Vector<Float> retval = new Vector<Float>();
    ThreadFactory tf = Executors.defaultThreadFactory();
    double gamma = Double.parseDouble(localprops.getProperty(GAMMAKEY));
    ArrayList<Thread> threads = new ArrayList<Thread>();
    ArrayList<HashSet<Integer>> threadrows = new ArrayList<HashSet<Integer>>();

    int interval = (int) Math.ceil((cfds.size() - 1) / (double) maxnumthreads);
    int left = 0;
    int right = cfds.size() - 2;
    HashSet<Integer> curset = null;
    boolean addLeftFirst = true;

    while (left <= right) {
        if (curset == null) {
            curset = new HashSet<Integer>();
        }

        if (curset.size() == interval) {
            threadrows.add(curset);
            curset = null;
        } else {
            if (addLeftFirst) {
                curset.add(left++);
            } else {
                curset.add(right--);
            }
            addLeftFirst = !addLeftFirst;

            if (curset.size() == interval) {
                continue;
            }

            if (addLeftFirst) {
                curset.add(left++);
            } else {
                curset.add(right--);
            }
        }
    }
    if (curset != null && curset.size() > 0) {
        threadrows.add(curset);
    }

    ArrayList<Vector<Float>> resultsList = new ArrayList<Vector<Float>>(cfds.size());
    // this is necessary to make sure that the proper indexes exist in
    // resultsList before being accessed by the threads
    for (int i = 0; i < cfds.size() - 1; i++) {
        resultsList.add(null);
    }

    for (int i = 0; i < threadrows.size(); i++) {
        Thread t = tf.newThread(new DistanceMatrixCalculator(gamma, threadrows.get(i), cfds, resultsList));
        threads.add(t);
    }

    for (Thread t : threads) {
        t.start();
    }

    for (Thread t : threads) {
        try {
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    for (int i = 0; i < resultsList.size(); i++) {
        retval.addAll(resultsList.get(i));
    }

    return retval;
}

From source file:org.apache.nifi.bootstrap.RunNiFi.java

public RunNiFi(final File bootstrapConfigFile, final boolean verbose) throws IOException {
    this.bootstrapConfigFile = bootstrapConfigFile;

    loggingExecutor = Executors.newFixedThreadPool(2, new ThreadFactory() {
        @Override//from  w w w  .  j ava 2 s. c  o  m
        public Thread newThread(final Runnable runnable) {
            final Thread t = Executors.defaultThreadFactory().newThread(runnable);
            t.setDaemon(true);
            t.setName("NiFi logging handler");
            return t;
        }
    });

    serviceManager = loadServices();
}

From source file:org.chililog.server.workbench.WorkbenchService.java

/**
 * Start the web server// w  w w  .jav a 2s  .com
 */
public synchronized void start() {
    AppProperties appProperties = AppProperties.getInstance();

    if (_channelFactory != null) {
        _logger.info("Workbench Web Sever Already Started.");
        return;
    }

    if (!appProperties.getWorkbenchEnabled()) {
        _logger.info("Workbench Web Sever not enabled and will not be started.");
        return;
    }

    _logger.info("Starting Workbench Web Sever on " + appProperties.getWorkbenchHost() + ":"
            + appProperties.getWorkbenchPort() + "...");

    // Create socket factory
    int workerCount = appProperties.getWorkbenchNettyWorkerThreadPoolSize();
    if (workerCount == 0) {
        _channelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool());
    } else {
        _channelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool(), workerCount);
    }

    // Configure the server
    ServerBootstrap bootstrap = new ServerBootstrap(_channelFactory);

    // Setup thread pool to run our handler
    // It makes sure the events from the same Channel are executed sequentially; i.e. event 1 is executed before
    // event 2. However event 1 may be executed on a different thread to event 2.
    OrderedMemoryAwareThreadPoolExecutor pipelineExecutor = new OrderedMemoryAwareThreadPoolExecutor(
            appProperties.getWorkbenchNettyHandlerThreadPoolSize(),
            appProperties.getWorkbenchNettyHandlerThreadPoolMaxChannelMemorySize(),
            appProperties.getWorkbenchNettyHandlerThreadPoolMaxTotalMemorySize(),
            appProperties.getWorkbenchNettyHandlerThreadPoolKeepAliveSeconds(), TimeUnit.SECONDS,
            Executors.defaultThreadFactory());

    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(new HttpServerPipelineFactory(pipelineExecutor));

    // Bind and start to accept incoming connections.
    String[] hosts = TransportConfiguration.splitHosts(appProperties.getWorkbenchHost());
    for (String h : hosts) {
        if (StringUtils.isBlank(h)) {
            if (hosts.length == 1) {
                h = "0.0.0.0";
            } else {
                continue;
            }
        }

        SocketAddress address = h.equals("0.0.0.0") ? new InetSocketAddress(appProperties.getWorkbenchPort())
                : new InetSocketAddress(h, appProperties.getWorkbenchPort());
        Channel channel = bootstrap.bind(address);
        _allChannels.add(channel);
    }

    _logger.info("Workbench Web Sever Started.");
}

From source file:org.apache.nifi.ldap.tenants.LdapUserGroupProvider.java

@Override
public void initialize(final UserGroupProviderInitializationContext initializationContext)
        throws AuthorizerCreationException {
    ldapSync = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        final ThreadFactory factory = Executors.defaultThreadFactory();

        @Override/*  ww  w  . j av a 2s . com*/
        public Thread newThread(Runnable r) {
            final Thread thread = factory.newThread(r);
            thread.setName(String.format("%s (%s) - background sync thread", getClass().getSimpleName(),
                    initializationContext.getIdentifier()));
            return thread;
        }
    });
}

From source file:org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.java

@Override
public void initialize(final UserGroupProviderInitializationContext initializationContext)
        throws SecurityProviderCreationException {
    ldapSync = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        final ThreadFactory factory = Executors.defaultThreadFactory();

        @Override// ww  w  .  j ava 2  s .c  om
        public Thread newThread(Runnable r) {
            final Thread thread = factory.newThread(r);
            thread.setName(String.format("%s (%s) - background sync thread", getClass().getSimpleName(),
                    initializationContext.getIdentifier()));
            return thread;
        }
    });
}

From source file:org.apache.nifi.processors.standard.ExecuteProcess.java

@OnScheduled
public void setupExecutor(final ProcessContext context) {
    executor = Executors.newFixedThreadPool(context.getMaxConcurrentTasks() * 2, new ThreadFactory() {
        private final ThreadFactory defaultFactory = Executors.defaultThreadFactory();

        @Override/* ww w .ja  va  2 s .  com*/
        public Thread newThread(final Runnable r) {
            final Thread t = defaultFactory.newThread(r);
            t.setName("ExecuteProcess " + getIdentifier() + " Task");
            return t;
        }
    });
}