Example usage for java.lang Thread setName

List of usage examples for java.lang Thread setName

Introduction

In this page you can find the example usage for java.lang Thread setName.

Prototype

public final synchronized void setName(String name) 

Source Link

Document

Changes the name of this thread to be equal to the argument name .

Usage

From source file:org.apache.hadoop.hbase.master.MasterMobCompactionThread.java

public MasterMobCompactionThread(HMaster master) {
    this.master = master;
    this.conf = master.getConfiguration();
    final String n = Thread.currentThread().getName();
    // this pool is used to run the mob compaction
    this.masterMobPool = new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
            new ThreadFactory() {
                @Override/*from   ww  w.ja va  2 s. com*/
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(n + "-MasterMobCompaction-" + EnvironmentEdgeManager.currentTime());
                    return t;
                }
            });
    ((ThreadPoolExecutor) this.masterMobPool).allowCoreThreadTimeOut(true);
    // this pool is used in the mob compaction to compact the mob files by partitions
    // in parallel
    this.mobCompactorPool = MobUtils.createMobCompactorThreadPool(master.getConfiguration());
}

From source file:org.apache.hadoop.hbase.master.MasterMobFileCompactionThread.java

public MasterMobFileCompactionThread(HMaster master) {
    this.master = master;
    this.conf = master.getConfiguration();
    final String n = Thread.currentThread().getName();
    // this pool is used to run the mob file compaction
    this.masterMobPool = new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
            new ThreadFactory() {
                @Override/*from  w w w.  j  av  a2  s. co  m*/
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(n + "-MasterMobFileCompaction-" + EnvironmentEdgeManager.currentTime());
                    return t;
                }
            });
    ((ThreadPoolExecutor) this.masterMobPool).allowCoreThreadTimeOut(true);
    // this pool is used in the mob file compaction to compact the mob files by partitions
    // in parallel
    this.mobFileCompactorPool = MobUtils.createMobFileCompactorThreadPool(master.getConfiguration());
}

From source file:net.pms.medialibrary.commons.helpers.FileImportHelper.java

/**
 * The file info objects will be updated according to the rules defined in 
 * the importConfig.//w w  w.  j  av  a2s .com
 * @param importConfig defines which plugins will be used to update fields in fileInfo
 * @param fileInfo the video that will be updated witch additional information
 * @param async the operation will be performed asynchronously if true; synchronously if false
 */
public static void updateFileInfos(final DOFileImportTemplate importConfig, final List<DOFileInfo> fileInfos,
        boolean async, final IProgress callback) {
    if (async) {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                updateFileInfosInternal(importConfig, fileInfos, callback);
            }
        };
        Thread th = new Thread(r);
        th.setName("update" + updateThreadCounter++);
        th.start();
    } else {
        updateFileInfosInternal(importConfig, fileInfos, callback);
    }
}

From source file:org.apache.synapse.commons.throttle.core.ThrottleWindowReplicator.java

public ThrottleWindowReplicator() {

    String replicatorThreads = System.getProperty(WINDOW_REPLICATOR_POOL_SIZE);

    if (replicatorThreads != null) {
        replicatorPoolSize = Integer.parseInt(replicatorThreads);
    }/*w w  w. j a  v a2s  .c om*/

    if (log.isDebugEnabled()) {
        log.debug("Throttle window replicator pool size set to " + replicatorPoolSize);
    }

    ScheduledExecutorService executor = Executors.newScheduledThreadPool(replicatorPoolSize,
            new ThreadFactory() {
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName("Throttle window replicator - " + replicatorCount++);
                    return t;
                }
            });

    String windowReplicationFrequency = System.getProperty(WINDOW_REPLICATOR_FREQUENCY);
    if (windowReplicationFrequency == null) {
        windowReplicationFrequency = "50";
    }

    if (log.isDebugEnabled()) {
        log.debug("Throttling window replication frequency set to " + windowReplicationFrequency);
    }

    for (int i = 0; i < replicatorPoolSize; i++) {
        executor.scheduleAtFixedRate(new ReplicatorTask(), Integer.parseInt(windowReplicationFrequency),
                Integer.parseInt(windowReplicationFrequency), TimeUnit.MILLISECONDS);
    }
}

From source file:org.xwiki.extension.job.history.internal.DefaultExtensionJobHistory.java

@Override
public void initialize() throws InitializationException {
    load();/*from ww w  .ja  v  a 2  s.c o  m*/

    Thread saveThread = new Thread(new SaveRunnable());
    saveThread.setName("XWiki's extension job history saving thread");
    saveThread.setDaemon(true);
    saveThread.setPriority(Thread.MIN_PRIORITY);
    saveThread.start();
}

From source file:net.dries007.holoInventory.client.ClientHandler.java

public void init() {
    MinecraftForge.EVENT_BUS.register(Renderer.INSTANCE);

    MinecraftForge.EVENT_BUS.register(KEY_MANAGER);

    if (HoloInventory.getConfig().doVersionCheck) {
        Thread vc = new Thread(VERSION_CHECK);
        vc.setDaemon(true);/*from   ww w.j  av  a  2 s. c  om*/
        vc.setName(Data.MODID + "VersionCheckThread");
        vc.run();

        MinecraftForge.EVENT_BUS.register(this);
    }
}

From source file:org.apache.axis2.clustering.tribes.AtMostOnceInterceptor.java

public AtMostOnceInterceptor() {
    Thread cleanupThread = new Thread(new MessageCleanupTask());
    cleanupThread.setPriority(Thread.MIN_PRIORITY);
    cleanupThread.setName("AtMostOnceInterceptor:Message-cleanup-thread"); // for debugging purposes
    cleanupThread.start();//from w ww  .ja  v a  2s . co m
}

From source file:org.drftpd.tests.ConnectionStressTest.java

public void testStress() {
    int i = 0;// ww w .ja  v  a  2 s.  com
    for (; i < 200; i++) {
        Thread t = new Thread(new DummyClient(this));

        list.add(t);

        t.start();
        t.setName("DummyClient-" + i);
        logger.debug("Launching DummyClient #" + i);

        try {
            Thread.sleep(100); //give the daemon some time.   
        } catch (InterruptedException e) {
            logger.fatal(e, e);
        }
    }

    assertTrue(success == i); // means that every attemp was successful when connecting

    Collections.reverse(list); // must reverse the order in order to iterate thru the first client firstly.

    int dead = 0;
    for (Thread t : list) {
        while (t.isAlive()) {
            // shotdown gracefully.
        }
        dead += 1;
    }

    assertTrue(dead == success); // all threads were finalized.
}

From source file:com.legalsoft.generic.gtc.controller.TimerBooleanController.java

/**
 * Mtodo para ejecutar este controller.//w ww . jav  a  2s .com
 */
@Override
public void run() {
    // Cambiar el nombre del thread.
    Thread thread = Thread.currentThread();
    thread.setName("TIMER");
    logger.info("Ejecutando el hilo del Timer @{}", Main.get_TS());
    // ejecutar en un bloque controlado.
    try {
        while (!thread.isInterrupted()) {
            // obtener el delay... en un bloque sincronizado.
            long cicleDelay;
            synchronized (delay) {
                cicleDelay = delay[0];
            }
            // ahora, una espera con este delay.
            Thread.sleep(cicleDelay);
            // Luego, llamar a los listeners.
            // el clculo del resultado es sincronizado.
            boolean result = calculateResult();
            fireTimerEvent(result);
        }
    } catch (InterruptedException exception) {
        logger.error("Ejecucin interrumpida: {}", exception);
        // terminando....
        thread.interrupt();
    }
    logger.info("Terminada la ejecucion del Timer @{}", Main.get_TS());
}

From source file:com.amazonaws.eclipse.core.accounts.profiles.SdkCredentialsFileContentMonitor.java

public SdkCredentialsFileContentMonitor(File target, long pollingIntervalInMillis,
        FileAlterationListener listener) {

    _target = target;//from   ww w .j av  a  2s  .c o  m

    // IllegalArgumentException is expected if target.getParentFile == null
    _observer = new FileAlterationObserver(target.getParentFile(), new FileFilter() {
        public boolean accept(File file) {
            return file.equals(_target);
        }
    });

    _monitor = new FileAlterationMonitor(pollingIntervalInMillis);
    _listener = listener;

    _observer.addListener(_listener);
    _monitor.addObserver(_observer);

    // Use daemon thread to avoid thread leakage
    _monitor.setThreadFactory(new ThreadFactory() {
        public Thread newThread(Runnable runnable) {
            Thread t = new Thread(runnable);
            t.setDaemon(true);
            t.setName("aws-credentials-file-monitor-thread");
            return t;
        }
    });
}