Search in sources :

Example 6 with SaturnThreadFactory

use of com.vip.saturn.job.threads.SaturnThreadFactory in project Saturn by vipshop.

the class RestartAndDumpService method initRestart.

private void initRestart() throws Exception {
    restartES = Executors.newSingleThreadExecutor(new SaturnThreadFactory(executorName + "-restart-watcher-thread", false));
    // Remove the restart node, before add watcher that watches the create and update event
    String nodePath = SaturnExecutorsNode.EXECUTORS_ROOT + "/" + executorName + "/restart";
    coordinatorRegistryCenter.remove(nodePath);
    restartNC = new NodeCache(curatorFramework, nodePath);
    restartNC.getListenable().addListener(new NodeCacheListener() {

        @Override
        public void nodeChanged() throws Exception {
            // Watch create, update event
            if (restartNC.getCurrentData() != null) {
                LogUtils.info(log, LogEvents.ExecutorEvent.RESTART, "The executor {} restart event is received", executorName);
                restartES.execute(new Runnable() {

                    @Override
                    public void run() {
                        executeRestartOrDumpCmd("restart", LogEvents.ExecutorEvent.RESTART);
                    }
                });
            }
        }
    });
    // Start, with not buildInitial.
    // The initial data is null, so the create event will be triggered firstly.
    restartNC.start(false);
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) SaturnThreadFactory(com.vip.saturn.job.threads.SaturnThreadFactory) SaturnJobException(com.vip.saturn.job.exception.SaturnJobException)

Example 7 with SaturnThreadFactory

use of com.vip.saturn.job.threads.SaturnThreadFactory in project Saturn by vipshop.

the class JobScheduler method initExecutorService.

private void initExecutorService() {
    ThreadFactory factory = new SaturnThreadFactory(jobName);
    executorService = new ExtendableThreadPoolExecutor(0, 100, 2, TimeUnit.MINUTES, new TaskQueue(), factory);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) SaturnThreadFactory(com.vip.saturn.job.threads.SaturnThreadFactory) ExtendableThreadPoolExecutor(com.vip.saturn.job.threads.ExtendableThreadPoolExecutor) TaskQueue(com.vip.saturn.job.threads.TaskQueue) SaturnThreadFactory(com.vip.saturn.job.threads.SaturnThreadFactory)

Example 8 with SaturnThreadFactory

use of com.vip.saturn.job.threads.SaturnThreadFactory in project Saturn by vipshop.

the class TimeoutSchedulerExecutor method createScheduler.

public static synchronized ScheduledThreadPoolExecutor createScheduler(String executorName) {
    if (!scheduledThreadPoolExecutorMap.containsKey(executorName)) {
        ScheduledThreadPoolExecutor timeoutExecutor = new ScheduledThreadPoolExecutor(Math.max(2, Runtime.getRuntime().availableProcessors() / 2), new SaturnThreadFactory(executorName + "-timeout-watchdog", false));
        timeoutExecutor.setRemoveOnCancelPolicy(true);
        scheduledThreadPoolExecutorMap.put(executorName, timeoutExecutor);
        return timeoutExecutor;
    }
    return scheduledThreadPoolExecutorMap.get(executorName);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SaturnThreadFactory(com.vip.saturn.job.threads.SaturnThreadFactory)

Aggregations

SaturnThreadFactory (com.vip.saturn.job.threads.SaturnThreadFactory)8 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)3 SaturnJobException (com.vip.saturn.job.exception.SaturnJobException)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 NodeCache (org.apache.curator.framework.recipes.cache.NodeCache)2 NodeCacheListener (org.apache.curator.framework.recipes.cache.NodeCacheListener)2 TimeDiffIntolerableException (com.vip.saturn.job.exception.TimeDiffIntolerableException)1 ExtendableThreadPoolExecutor (com.vip.saturn.job.threads.ExtendableThreadPoolExecutor)1 TaskQueue (com.vip.saturn.job.threads.TaskQueue)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ChildData (org.apache.curator.framework.recipes.cache.ChildData)1 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)1 Type (org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type)1 TreeCacheListener (org.apache.curator.framework.recipes.cache.TreeCacheListener)1 ConnectionState (org.apache.curator.framework.state.ConnectionState)1 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)1 CloseableExecutorService (org.apache.curator.utils.CloseableExecutorService)1