Example usage for java.util.concurrent ThreadFactory ThreadFactory

List of usage examples for java.util.concurrent ThreadFactory ThreadFactory

Introduction

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

Prototype

ThreadFactory

Source Link

Usage

From source file:edu.umass.cs.gigapaxos.FailureDetection.java

FailureDetection(NodeIDType id, InterfaceNIOTransport<NodeIDType, JSONObject> niot, String paxosLogFolder) {
    nioTransport = niot;/*from   w ww  .j  a  v  a  2 s  .  c  o m*/
    myID = id;
    this.execpool = Executors.newScheduledThreadPool(1, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread thread = Executors.defaultThreadFactory().newThread(r);
            thread.setName(FailureDetection.class.getSimpleName() + myID);
            return thread;
        }
    });
    lastHeardFrom = new ConcurrentHashMap<NodeIDType, Long>();
    keepAliveTargets = new TreeSet<NodeIDType>();
    futures = new HashMap<NodeIDType, ScheduledFuture<PingTask>>();
    initialize(paxosLogFolder);
}

From source file:com.espertech.esper.timer.TimerServiceImpl.java

private void getScheduledThreadPoolExecutorDaemonThread() {
    timer = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
        // set new thread as daemon thread and name appropriately
        public Thread newThread(Runnable r) {
            String uri = engineURI;
            if (engineURI == null) {
                uri = "default";
            }// w ww .  j  a  va 2  s. c o  m
            Thread t = new Thread(r, "com.espertech.esper.Timer-" + uri + "-" + id);
            t.setDaemon(true);
            return t;
        }
    });
    timer.setMaximumPoolSize(timer.getCorePoolSize());
    timer.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    timer.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
}

From source file:com.asprise.imaging.core.Imaging.java

/** Use this executor service to make sure that all scanning related code is executed from the same thread. */
public static ExecutorService getDefaultExecutorServiceForScanning() {
    if (executorServiceForScanning == null) {
        synchronized (Imaging.class) {
            if (executorServiceForScanning == null) {
                executorServiceForScanning = Executors.newSingleThreadExecutor(new ThreadFactory() { // custom factory for user-friendly thread name
                    final AtomicInteger threadNumber = new AtomicInteger(1);
                    ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory();

                    @Override/*w ww.j  av  a  2 s.  com*/
                    public Thread newThread(Runnable r) {
                        Thread thread = defaultThreadFactory.newThread(r);
                        thread.setName("scan" + (threadNumber.get() == 1 ? "" : "-" + threadNumber));
                        return thread;
                    }
                });
            }
        }
    }
    return executorServiceForScanning;
}

From source file:edu.umass.cs.nio.AbstractPacketDemultiplexer.java

/**
 * //w ww .j a va2  s  . co m
 * @param threadPoolSize
 *            Refer documentation for {@link #setThreadPoolSize(int)
 *            setThreadPoolsize(int)}.
 */
public AbstractPacketDemultiplexer(int threadPoolSize) {
    this.executor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(threadPoolSize,
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = Executors.defaultThreadFactory().newThread(r);
                    thread.setName(threadName);
                    return thread;
                }
            });
    this.myThreadPoolSize = threadPoolSize;
}

From source file:org.apache.hadoop.registry.server.services.RegistryAdminService.java

/**
 * construct an instance of the service, using the
 * specified binding source to bond to ZK
 * @param name service name//  w w w  . j a v  a 2  s  .c  o  m
 * @param bindingSource provider of ZK binding information
 */
public RegistryAdminService(String name, RegistryBindingSource bindingSource) {
    super(name, bindingSource);
    executor = Executors.newCachedThreadPool(new ThreadFactory() {
        private AtomicInteger counter = new AtomicInteger(1);

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "RegistryAdminService " + counter.getAndIncrement());
        }
    });
}

From source file:com.reactive.hzdfs.dll.AbstractFileSharingService.java

private void startHandlers() {
    threads = Executors.newSingleThreadExecutor(new ThreadFactory() {
        @Override//from  w  w w.ja  v a2  s  .  co  m
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, "FileSharingAgent.Worker");
            return t;
        }
    });

}

From source file:org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl.java

@PostConstruct
public void initialize() {
    executorService = Executors.newCachedThreadPool(new ThreadFactory() {
        @Override//from  ww w  .ja  v a 2s.  c  om
        public Thread newThread(Runnable r) {
            return new Thread(r, "SPARQL Query Thread " + (++queryId));
        }
    });
}

From source file:com.opendoorlogistics.core.gis.map.background.MapsforgeTileFactory.java

MapsforgeTileFactory(TileFactoryInfo info, String xmlRenderThemeFilename, MapDataStore mapDatabase,
        FadeConfig fadeColour) {//from w  w w.j a  va2s .c  o  m
    super(info);
    this.fadeColour = fadeColour;
    this.mapDatabase = mapDatabase;

    zoomLevelConverter = new ZoomLevelConverter(info);
    databaseRenderer = new DatabaseRenderer(mapDatabase, AwtGraphicFactory.INSTANCE,
            createDummyTileCacheForMapsforgeLabelPlacementAlgorithm());
    renderTheme = getRenderTheme(xmlRenderThemeFilename);

    model = new DisplayModel();
    model.setFixedTileSize(TILE_SIZE);
    model.setBackgroundColor(backgroundMapColour().getRGB());

    // use single thread at the moment as DatabaseRenderer is probably single threaded
    service = Executors.newFixedThreadPool(1, new ThreadFactory() {
        private int count = 0;

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, "mapsforge-tile-pool-" + count++);
            t.setPriority(Thread.MIN_PRIORITY);
            t.setDaemon(true);
            return t;
        }
    });
}

From source file:org.wso2.carbon.bpel.b4p.coordination.CoordinationController.java

private ThreadFactory createThreadFactory() {
    return new ThreadFactory() {
        private int threadNumber = 0;

        public Thread newThread(Runnable r) {
            threadNumber += 1;//from  www. java2s.  c  o m
            Thread t = new Thread(r, "B4PCoordination-" + threadNumber);
            t.setDaemon(true);
            return t;
        }
    };
}

From source file:com.linkedin.pinot.controller.helix.SegmentStatusChecker.java

private void startThread() {
    LOGGER.info("Starting segment status checker");

    if (_executorService == null) {
        _executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
            @Override// w ww  .  j  a v  a2 s. c  o  m
            public Thread newThread(Runnable runnable) {
                Thread thread = new Thread(runnable);
                thread.setName("SegStatChecker");
                return thread;
            }
        });
        // Set up an executor that executes segment status tasks periodically
        _executorService.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                try {
                    runSegmentMetrics();
                } catch (Exception e) {
                    LOGGER.warn("Caught exception while running segment status checker", e);
                }
            }
        }, SegmentCheckerDefaultIntervalSeconds, _segmentStatusIntervalSeconds, TimeUnit.SECONDS);
    } else {
        LOGGER.warn("SegmentStatusChecker already running. Attempt to start a duplicate thread");
    }
}