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.hdfs.server.datanode.DataXceiverThreadPool.java

/**
 * Create a pool of threads to do disk IO.
 * //from w  ww.jav  a 2 s .  co  m
 * @param conf The configuration
 * @param tg The ThreadGroup of all the executor threads
 * @param maxXceiverCount The max number of threads that can do IO.
 */
DataXceiverThreadPool(final Configuration conf, final ThreadGroup tg, final int maxXceiverCount) {

    ThreadFactory threadFactory = new ThreadFactory() {
        int counter = 0;

        @Override
        public Thread newThread(Runnable r) {
            int thisIndex;
            synchronized (this) {
                thisIndex = counter++;
            }
            Thread t = new Thread(tg, r);
            t.setName("disk io thread #" + thisIndex);
            t.setDaemon(true);
            return t;
        }
    };

    executor = new ThreadPoolExecutor(maxXceiverCount - 1, maxXceiverCount, THREADS_KEEP_ALIVE_SECONDS,
            TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory);

    // This can reduce the number of running threads
    executor.allowCoreThreadTimeOut(true);
}

From source file:io.gravitee.gateway.standalone.Container.java

/**
 * Stop a new gravitee instance node./*  w ww  .j  a v a 2s  . co  m*/
 */
public void start() {
    LoggerFactory.getLogger(Container.class).info("Start Gravitee Gateway...");

    try {
        node.start();

        // Register shutdown hook
        Thread shutdownHook = new ContainerShutdownHook();
        shutdownHook.setName("gravitee-finalizer");
        Runtime.getRuntime().addShutdownHook(shutdownHook);
    } catch (Exception ex) {
        LoggerFactory.getLogger(Container.class).error("An unexpected error occurs while starting gateway", ex);
        stop();
    }
}

From source file:de.doering.dwca.flickr.OccurrenceExport.java

private Thread startThread(int year) {
    Runnable searcher = new ExtractYear(year, imgWriter);
    Thread worker = new Thread(searcher);
    // We can set the name of the thread
    worker.setName("searcher" + year);
    // Start the thread, never call method run() direct
    log.debug("Searching year " + year);
    worker.start();/*from w ww .j a  v a2 s .co m*/
    return worker;
}

From source file:com.alibaba.wasp.fserver.SplitThread.java

/** @param server */
SplitThread(FServer server) {/*  ww w  .  j  av  a 2  s. c o  m*/
    super();
    this.server = server;
    this.conf = server.getConfiguration();
    this.entityGroupSplitLimit = conf.getInt("wasp.fserver.entityGroupSplitLimit", Integer.MAX_VALUE);

    int splitThreads = conf.getInt("wasp.fserver.thread.split", 1);

    final String n = Thread.currentThread().getName();

    this.splits = (ThreadPoolExecutor) Executors.newFixedThreadPool(splitThreads, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName(n + "-splits-" + System.currentTimeMillis());
            return t;
        }
    });
}

From source file:com.moss.appsnap.keeper.Poller.java

public void start() {
    Thread t = new Thread(this);
    t.setName("Polling thread");
    t.start();//w  w  w  .j a  v a  2 s.  com
}

From source file:org.rhq.core.util.exec.StreamRedirectorRunnable.java

/**
 * @see java.lang.Runnable#run()//w  w w .  j a  v  a  2 s.co  m
 */
@Override
public void run() {
    Thread thread = Thread.currentThread();
    thread.setName(m_name);

    final int bufferSize = 4096;
    byte[] buffer = new byte[bufferSize];

    try {
        while (Thread.interrupted() != true) {
            int read = m_input.read(buffer, 0, bufferSize);
            // check for EOF
            if (read < 0) {
                LOG.debug("Reached EOF on input stream"); //$NON-NLS-1$
                break;
            }
            // do redirection
            if (read > 0 && m_output != null) {
                m_output.write(buffer, 0, read);
            }
        }
    } catch (Throwable t) {
        LOG.warn("An unexpected error occurred while redirecting stream output: " + t.getMessage(), t); //$NON-NLS-1$
    } finally {
        // finished reading the input, close the streams and exit the thread
        try {
            m_input.close();
        } catch (IOException e) {
            // we do not care if close fails as there is nothing we can do
        }
        try {
            if (m_output != null) {
                m_output.close();
            }
        } catch (IOException e) {
            // we do not care if close fails as there is nothing we can do
        }
    }

    return;
}

From source file:net.sf.jabref.JabRefExecutorService.java

public void executeWithLowPriorityInOwnThreadAndWait(Runnable runnable) {
    Thread thread = new Thread(runnable);
    thread.setName("JabRef low prio");
    startedThreads.add(thread);//from w ww . j  a v a2 s. c o m
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.start();

    waitForThreadToFinish(thread);
}

From source file:edu.fullerton.framemonitor.FrameMonitor.java

public void startTasks() {
    PrintStream log = System.out;

    // Built in watchers are very efficient but only work for native file systems 
    // But they do not work on nfs volumes
    for (PlotQueDefn pqd : watchQueDefn) {
        File dir = new File(pqd.getDirName());
        if (!dir.exists()) {
            System.err.println("Directory: " + pqd.getDirName() + " does not exist.");
        } else {/*from  w  w w  .  j  av a  2 s .co m*/
            // create a list of queues that will process the files found
            BlockingQueue<File> outQue = new ArrayBlockingQueue<>(128);
            List<BlockingQueue<File>> fileQueue = new ArrayList<>();
            fileQueue.add(outQue);

            // create the processes that will consume the queues
            QueueProcessor pq = new IgnoreQueue(outQue, log);
            Thread pqt = new Thread(pq);
            pqt.setName(pqd.getQueName() + " - consumer");
            pqt.start();
            processors.add(pqt);

            FrameWatcher w = new FrameWatcher(pqd.getDirName(), pqd.getFrameType(), log, fileQueue);
            Thread wt = new Thread(w);
            wt.setName(pqd.getQueName() + " - watcher");
            wt.start();
            watchers.add(wt);
        }
    }
    // The Apache commons listeners poll so they also work on nfs volumes
    for (PlotQueDefn pqd : listenQueDefn) {
        File dir = new File(pqd.getDirName());
        if (!dir.exists()) {
            System.err.println("Directory: " + pqd.getDirName() + " does not exist.");
        } else {
            // create a list of queues that will process the files found
            BlockingQueue<File> outQue = new ArrayBlockingQueue<>(128);
            List<BlockingQueue<File>> fileQueue = new ArrayList<>();
            fileQueue.add(outQue);

            // create the processes that will consume the queues
            QueueProcessor pq = new IgnoreQueue(outQue, log);
            Thread pqt = new Thread(pq);
            pqt.setName(pqd.getQueName() + " - consumer");
            pqt.start();
            processors.add(pqt);

            FileAlterationObserver observer = new FileAlterationObserver(pqd.getDirName());
            ChangeListener cl = new ChangeListener(log, outQue);
            observer.addListener(cl);
            monitor.addObserver(observer);
        }
    }
    try {
        monitor.start();
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    System.out.println("Stopping monitor.");
                    monitor.stop();
                } catch (Exception ignored) {
                }
            }
        }));
    } catch (Exception ex) {
        Logger.getLogger(FrameMonitor.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.commonjava.indy.ftest.core.AbstractContentManagementTest.java

protected Thread newThread(final String named, final Runnable runnable) {
    final Thread t = new Thread(runnable);
    t.setDaemon(true);//from   www.  j  a  va 2s. c  om
    t.setName(name.getMethodName() + " :: " + named);

    return t;
}

From source file:com.fluke.data.processor.ReatimeDBReader.java

@Override
public void run() {

    try {/*from   www  .j  av  a2  s . c  om*/
        this.getAllEquity().stream().forEach(v -> {
            RediffParser parser = new RediffParser(v, "2015-09-23");
            Thread thread = new Thread(parser);
            thread.setName(v);
            thread.start();
        });
    } catch (SQLException ex) {
        throw new RuntimeException(ex);
    }

}