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:Main.java

/**
 * Based on the default thread factory/* w  ww  .j a  va 2s  . c om*/
 *
 * @param name
 *            the name prefix of the new thread
 * @return the factory to use when creating new threads
 */
public static final ThreadFactory getThreadFactory(String name) {
    return r -> {
        Thread t = Executors.defaultThreadFactory().newThread(r);
        t.setName(name + "-" + t.getName()); //$NON-NLS-1$
        return t;
    };
}

From source file:org.apache.hadoop.hbase.PerformanceEvaluationCommons.java

public static void concurrentReads(final Runnable r) {
    final int count = 1;
    long now = System.currentTimeMillis();
    List<Thread> threads = new ArrayList<Thread>(count);
    for (int i = 0; i < count; i++) {
        Thread t = new Thread(r);
        t.setName("" + i);
        threads.add(t);/*from www  .  j  a va2  s  . co  m*/
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        try {
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    LOG.info("Test took " + (System.currentTimeMillis() - now));
}

From source file:com.carl.interesting.StartINGServer.java

/**
 * Mapping MEMORY_MAP_FILE into memory for communicating with external.
 * /*from w ww .  j a  v  a 2s .c  om*/
 * @throws IOException [explain parameter]
 * @return void [explain return type]
 * @exception throws [exception type] [explain exception]
 * @see [class,class#method,class#member]
 */
private static void initServer() throws IOException {
    BASE = KeyConstant.MICROSERVICE_HOST;
    PORT = Integer.parseInt(KeyConstant.MICROSERVICE_PORT);
    Thread messageThread = new MessageTask();
    messageThread.setName("messageThread");
    messageThread.start();
}

From source file:com.cueup.hegemon.TestUtils.java

public static void runConcurrent(int count, Runnable r) throws InterruptedException {
    List<Thread> threads = Lists.newArrayList();
    ErrorCollector errorCollector = new ErrorCollector();

    for (int i = 0; i < count; i++) {
        Thread t = new Thread(r);
        t.setName("testThread" + i);
        t.setUncaughtExceptionHandler(errorCollector);
        threads.add(t);//  w w w .j  ava  2  s . c om

    }

    for (Thread t : threads) {
        t.start();
    }

    for (Thread t : threads) {
        t.join();
    }

    errorCollector.assertNoErrors();
}

From source file:Main.java

/**
 * Utility method that sets name, daemon status and starts passed thread.
 * @param t thread to frob//from w  ww  .j ava 2s. co  m
 * @param name new name
 * @param handler A handler to set on the thread.  Pass null if want to
 * use default handler.
 * @return Returns the passed Thread <code>t</code>.
 */
public static Thread setDaemonThreadRunning(final Thread t, final String name,
        final UncaughtExceptionHandler handler) {
    t.setName(name);
    if (handler != null) {
        t.setUncaughtExceptionHandler(handler);
    }
    t.setDaemon(true);
    t.start();
    return t;
}

From source file:com.hurence.logisland.hadoop.SecurityUtil.java

/**
 * Start a thread that periodically attempts to renew the current Kerberos user's ticket.
 *
 * Callers of this method should store the reference to the KerberosTicketRenewer and call stop() to stop the thread.
 *
 * @param id/*ww w.ja  v  a 2 s  .  c  o  m*/
 *          The unique identifier to use for the thread, can be the class name that started the thread
 *              (i.e. PutHDFS, etc)
 * @param ugi
 *          The current Kerberos user.
 * @param renewalPeriod
 *          The amount of time between attempting renewals.
 * @param logger
 *          The logger to use with in the renewer
 *
 * @return the KerberosTicketRenewer Runnable
 */
public static KerberosTicketRenewer startTicketRenewalThread(final String id, final UserGroupInformation ugi,
        final long renewalPeriod, final ComponentLog logger) {
    final KerberosTicketRenewer renewer = new KerberosTicketRenewer(ugi, renewalPeriod, logger);

    final Thread t = new Thread(renewer);
    t.setName("Kerberos Ticket Renewal [" + id + "]");
    t.start();

    return renewer;
}

From source file:com.lightbox.android.bitmap.BitmapFileCleanerTask.java

private static ExecutorService getExecutor() {
    if (sBitmapFileCleanerExecutor == null) {
        sBitmapFileCleanerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
            @Override// w w w  .  j a  v  a  2  s . c  o m
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setName(TAG + " | " + thread.getName());
                thread.setPriority(Thread.MIN_PRIORITY);
                return thread;
            }
        });
    }
    return sBitmapFileCleanerExecutor;
}

From source file:com.connectsdk.core.Util.java

static void createExecutor() {
    Util.executor = Executors.newFixedThreadPool(NUM_OF_THREADS, new ThreadFactory() {
        @Override/*from  w  ww. ja  v  a2s.c om*/
        public Thread newThread(Runnable r) {
            Thread th = new Thread(r);
            th.setName("2nd Screen BG");
            return th;
        }
    });
}

From source file:com.nesscomputing.syslog4j.server.SyslogServer.java

public static final SyslogServerIF getThreadedInstance(String protocol) throws SyslogRuntimeException {
    SyslogServerIF server = getInstance(protocol);

    if (server.getThread() == null) {
        Thread thread = new Thread(server);
        thread.setName("SyslogServer: " + protocol);
        thread.setDaemon(server.getConfig().isUseDaemonThread());
        if (server.getConfig().getThreadPriority() > -1) {
            thread.setPriority(server.getConfig().getThreadPriority());
        }//from  w w  w . j av a 2  s .  c o m

        server.setThread(thread);
        thread.start();
    }

    return server;
}

From source file:immf.growl.GrowlNotifier.java

public static GrowlNotifier getInstance(GrowlApiClient clientConcrete, Config config) {
    if (clientConcrete != null && config != null) {

        GrowlNotifier notify = new GrowlNotifier();

        notify.client = clientConcrete;//from   w  w w.j a  v  a 2 s . c o  m

        notify.config = config;

        String apiKey = clientConcrete.getApiKeyFromConfig(config);

        if (apiKey != null && apiKey != "") {
            String[] apiKeyArray = apiKey.split(",");
            for (String key : apiKeyArray) {
                notify.growlApiKeyList.add(new GrowlKey(key));
            }

            if (notify.growlApiKeyList.size() > 0) {
                notify.client = clientConcrete;
                Thread t = new Thread(notify);
                t.setName(notify.client.getClass().getName());
                t.setDaemon(true);
                t.start();
            }
        }

        return notify;

    } else {
        return null;
    }
}