Search in sources :

Example 26 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project jersey by jersey.

the class TransportFilter method initializeChannelGroup.

private void initializeChannelGroup() throws IOException {
    if (closeWaitTask != null) {
        closeWaitTask.cancel(true);
        closeWaitTask = null;
    }
    if (channelGroup == null) {
        ThreadFactory threadFactory = threadPoolConfig.getThreadFactory();
        if (threadFactory == null) {
            threadFactory = new TransportThreadFactory(threadPoolConfig);
        }
        ExecutorService executor;
        if (threadPoolConfig.getQueue() != null) {
            executor = new QueuingExecutor(threadPoolConfig.getCorePoolSize(), threadPoolConfig.getMaxPoolSize(), threadPoolConfig.getKeepAliveTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, threadPoolConfig.getQueue(), false, threadFactory);
        } else {
            int taskQueueLimit = threadPoolConfig.getQueueLimit();
            if (taskQueueLimit == -1) {
                taskQueueLimit = Integer.MAX_VALUE;
            }
            executor = new QueuingExecutor(threadPoolConfig.getCorePoolSize(), threadPoolConfig.getMaxPoolSize(), threadPoolConfig.getKeepAliveTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>(taskQueueLimit), true, threadFactory);
        }
        // Thread pool is owned by the channel group and will be shut down when channel group is shut down
        channelGroup = AsynchronousChannelGroup.withCachedThreadPool(executor, threadPoolConfig.getCorePoolSize());
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService)

Example 27 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project jmxtrans by jmxtrans.

the class JmxTransModule method createExecutorService.

private ThreadPoolExecutor createExecutorService(int poolSize, int workQueueCapacity, String componentName) {
    BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(workQueueCapacity);
    ThreadFactory threadFactory = threadFactory(componentName);
    return new ThreadPoolExecutor(poolSize, poolSize, 0L, MILLISECONDS, workQueue, threadFactory);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 28 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project languagetool by languagetool-org.

the class LanguageToolSupport method init.

private void init() {
    try {
        config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, null);
    } catch (IOException ex) {
        throw new RuntimeException("Could not load configuration", ex);
    }
    Language defaultLanguage = config.getLanguage();
    if (defaultLanguage == null) {
        defaultLanguage = Languages.getLanguageForLocale(Locale.getDefault());
    }
    /**
     * Warm-up: we have a lot of lazy init in LT, which causes the first check to
     * be very slow (several seconds) for languages with a lot of data and a lot of
     * rules. We just assume that the default language is the language that the user
     * often uses and init the LT object for that now, not just when it's first used.
     * This makes the first check feel much faster:
     */
    reloadLanguageTool(defaultLanguage);
    checkExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setDaemon(true);
            t.setPriority(Thread.MIN_PRIORITY);
            t.setName(t.getName() + "-lt-background");
            return t;
        }
    });
    check = new AtomicInteger(0);
    this.textComponent.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            recalculateSpans(e.getOffset(), e.getLength(), false);
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            recalculateSpans(e.getOffset(), e.getLength(), true);
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }
    });
    mouseListener = new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent me) {
        }

        @Override
        public void mousePressed(MouseEvent me) {
            if (me.isPopupTrigger()) {
                showPopup(me);
            }
        }

        @Override
        public void mouseReleased(MouseEvent me) {
            if (me.isPopupTrigger()) {
                showPopup(me);
            }
        }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }
    };
    this.textComponent.addMouseListener(mouseListener);
    actionListener = e -> _actionPerformed(e);
    mustDetectLanguage = config.getAutoDetect();
    if (!this.textComponent.getText().isEmpty() && backgroundCheckEnabled) {
        checkImmediately(null);
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) MouseEvent(java.awt.event.MouseEvent) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) IOException(java.io.IOException) MouseListener(java.awt.event.MouseListener) Language(org.languagetool.Language) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File)

Example 29 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project pinpoint by naver.

the class StandbySpanStreamDataSendWorker method start.

public void start() {
    final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
    this.workerThread = threadFactory.newThread(this);
    logger.info("start() started.");
    if (!workerThread.isAlive()) {
        this.isStarted = true;
        this.workerThread.start();
        logger.info("start() completed.");
    } else {
        logger.info("start() failed. caused:already started.", this.getClass().getSimpleName());
    }
}
Also used : PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory)

Example 30 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project pinpoint by naver.

the class BufferedUdpDataSender method startScheduledFlush.

private Thread startScheduledFlush() {
    final ThreadFactory threadFactory = new PinpointThreadFactory(SCHEDULED_FLUSH, true);
    final Thread thread = threadFactory.newThread(new Runnable() {

        @Override
        public void run() {
            final Thread currentThread = Thread.currentThread();
            while (!currentThread.isInterrupted()) {
                try {
                    chunkHeaderBufferedSerializer.flush();
                } catch (TException e) {
                    logger.warn("Failed to flush. caused={}", e.getMessage(), e);
                }
                try {
                    TimeUnit.MILLISECONDS.sleep(1000);
                } catch (InterruptedException ignored) {
                    currentThread.interrupt();
                }
            }
            logger.info("stop ScheduledFlush {} - {}", currentThread.getName(), currentThread.getId());
        }
    });
    logger.info("stop ScheduledFlush {} - {}", thread.getName(), thread.getId());
    thread.start();
    return thread;
}
Also used : TException(org.apache.thrift.TException) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory)

Aggregations

ThreadFactory (java.util.concurrent.ThreadFactory)214 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)40 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)38 ExecutorService (java.util.concurrent.ExecutorService)35 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)28 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)18 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)18 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)14 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)13 LoggingThreadGroup (org.apache.geode.internal.logging.LoggingThreadGroup)12 Future (java.util.concurrent.Future)11 Test (org.junit.Test)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 ChannelFuture (io.netty.channel.ChannelFuture)8 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)8 ExecutionException (java.util.concurrent.ExecutionException)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 UdtChannel (io.netty.channel.udt.UdtChannel)6