Example usage for java.lang Thread getName

List of usage examples for java.lang Thread getName

Introduction

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

Prototype

public final String getName() 

Source Link

Document

Returns this thread's name.

Usage

From source file:eu.stratosphere.client.minicluster.NepheleMiniCluster.java

public void start() throws Exception {
    synchronized (startStopLock) {
        // set up the global configuration
        if (this.configDir != null) {
            GlobalConfiguration.loadConfiguration(configDir);
        } else {//from  w  ww. j  a va2s .c o  m
            Configuration conf = getMiniclusterDefaultConfig(jobManagerRpcPort, taskManagerRpcPort,
                    taskManagerDataPort, memorySize, hdfsConfigFile, lazyMemoryAllocation,
                    defaultOverwriteFiles, defaultAlwaysCreateDirectory, numTaskManager);
            GlobalConfiguration.includeConfiguration(conf);
        }

        // force the input/output format classes to load the default values from the configuration.
        // we need to do this here, because the format classes may have been initialized before the mini cluster was started
        initializeIOFormatClasses();

        // before we start the JobManager, we need to make sure that there are no lingering IPC threads from before
        // check that all threads are done before we return
        Thread[] allThreads = new Thread[Thread.activeCount()];
        int numThreads = Thread.enumerate(allThreads);

        for (int i = 0; i < numThreads; i++) {
            Thread t = allThreads[i];
            String name = t.getName();
            if (name.startsWith("IPC")) {
                t.join();
            }
        }

        // start the job manager
        jobManager = new JobManager(ExecutionMode.LOCAL);

        waitForJobManagerToBecomeReady(numTaskManager);
    }
}

From source file:org.guzz.service.core.impl.DebugServiceImpl.java

protected boolean isDemonThread() {
    Thread t = Thread.currentThread();

    //      return t.isDaemon() ;

    String name = t.getName();
    if (name == null)
        return false;

    return name.startsWith(DebugService.DEMON_NAME_PREFIX);
}

From source file:eu.stratosphere.nephele.profiling.impl.TaskManagerProfilerImpl.java

public void registerMainThreadForCPUProfiling(Environment environment, Thread thread,
        ExecutionVertexID executionVertexID) {

    synchronized (this.monitoredThreads) {
        LOG.debug("Registering thread " + thread.getName() + " for CPU monitoring");
        if (this.monitoredThreads.containsKey(environment)) {
            LOG.error("There is already a main thread registered for environment object "
                    + environment.getTaskName());
        }//from w  w  w  . j a va2s . c  om

        this.monitoredThreads.put(environment, new EnvironmentThreadSet(this.tmx, thread, executionVertexID));
    }
}

From source file:org.bonitasoft.engine.test.internal.EngineStarter.java

private boolean isExpectedThread(final Thread thread) {
    final String name = thread.getName();
    final ThreadGroup threadGroup = thread.getThreadGroup();
    if (threadGroup != null && threadGroup.getName().equals("system")) {
        return true;
    }/* ww  w  . j  av  a 2  s  .co m*/
    final List<String> startWithFilter = Arrays.asList("H2 ", "Timer-0" /* postgres driver related */,
            "bitronix", "main", "Reference Handler", "Signal Dispatcher", "Finalizer",
            "com.google.common.base.internal.Finalizer", "process reaper", "ReaderThread",
            "Abandoned connection cleanup thread", "Monitor Ctrl-Break"/* Intellij */, "daemon-shutdown",
            "surefire-forkedjvm", "Restlet");
    for (final String prefix : startWithFilter) {
        if (name.startsWith(prefix)) {
            return true;
        }
    }
    //shutdown hook not executed in main thread
    return thread.getId() == Thread.currentThread().getId();
}

From source file:org.openflamingo.remote.thrift.thriftfs.ThriftHandlerBase.java

/**
 * Return a list of threads that currently exist with their stack traces
 *//*from   w w  w  .j  a v  a 2s  .com*/
public List<ThreadStackTrace> getThreadDump(RequestContext ctx) {
    List<ThreadStackTrace> dump = new ArrayList<ThreadStackTrace>();

    Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
    for (Map.Entry<Thread, StackTraceElement[]> entry : traces.entrySet()) {
        final Thread t = entry.getKey();
        final StackTraceElement[] frames = entry.getValue();

        ThreadStackTrace tst = new ThreadStackTrace();
        tst.threadName = t.getName();
        tst.threadStringRepresentation = String.valueOf(t);
        tst.isDaemon = t.isDaemon();
        tst.stackTrace = new ArrayList<StackTraceElement>();
        for (StackTraceElement ste : frames) {
            StackTraceElement tFrame = new StackTraceElement();
            tFrame.className = ste.getClassName();
            tFrame.fileName = ste.getFileName();
            tFrame.lineNumber = ste.getLineNumber();
            tFrame.methodName = ste.getMethodName();
            tFrame.isNativeMethod = ste.isNativeMethod();
            tFrame.stringRepresentation = String.valueOf(ste);
            tst.stackTrace.add(tFrame);
        }
        dump.add(tst);
    }
    return dump;
}

From source file:org.apache.servicemix.nmr.core.ChannelImpl.java

/**
 * Synchronously send the exchange//  w  ww. j a  v a 2 s  . c  o m
 *
 * @param exchange the exchange to send
 * @param timeout  time to wait in milliseconds
 * @return <code>true</code> if the exchange has been processed succesfully
 */
public boolean sendSync(Exchange exchange, long timeout) {
    InternalExchange e = (InternalExchange) exchange;
    Semaphore lock = e.getRole() == Role.Consumer ? e.getConsumerLock(true) : e.getProviderLock(true);
    dispatch(e);
    Thread thread = Thread.currentThread();
    String original = thread.getName();
    try {
        if (timeout > 0) {
            if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
                throw new TimeoutException();
            }
        } else {
            thread.setName(original + " (waiting for exchange " + exchange.getId() + ")");
            lock.acquire();
        }
        e.setRole(e.getRole() == Role.Consumer ? Role.Provider : Role.Consumer);
    } catch (InterruptedException ex) {
        exchange.setError(ex);
        for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
            l.exchangeFailed(exchange);
        }
        return false;
    } catch (TimeoutException ex) {
        exchange.setError(new AbortedException(ex));
        for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
            l.exchangeFailed(exchange);
        }
        return false;
    } finally {
        thread.setName(original);
    }
    return true;
}

From source file:metlos.executors.batch.BatchCpuThrottlingExecutorTest.java

@Test
public void maxUsage_SingleThreaded() throws Exception {
    NamingThreadFactory factory = new NamingThreadFactory();
    ThreadPoolExecutor e = new ThreadPoolExecutor(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(),
            factory);//from  w  ww . j  a  va2 s .  c  o  m
    e.prestartAllCoreThreads();

    List<Future<?>> payloadResults = new ArrayList<Future<?>>();

    long startTime = System.nanoTime();

    //create load
    for (int i = 0; i < NOF_JOBS; ++i) {
        Future<?> f = e.submit(new Payload());
        payloadResults.add(f);
    }

    //wait for it all to finish
    for (Future<?> f : payloadResults) {
        f.get();
    }

    long endTime = System.nanoTime();

    long time = endTime - startTime;
    LOG.info("MAX Singlethreaded test took " + (time / 1000.0 / 1000.0) + "ms");

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long cpuTime = 0;
    for (Thread t : factory.createdThreads) {
        long threadCpuTime = threadBean.getThreadCpuTime(t.getId());
        LOG.info(t.getName() + ": " + threadCpuTime + "ns");
        cpuTime += threadCpuTime;
    }

    float actualUsage = (float) cpuTime / time;

    LOG.info("MAX Singlethreaded overall usage: " + actualUsage);
}

From source file:metlos.executors.batch.BatchCpuThrottlingExecutorTest.java

@Test
public void maxUsage_MultiThreaded() throws Exception {
    NamingThreadFactory factory = new NamingThreadFactory();
    ThreadPoolExecutor e = new ThreadPoolExecutor(10, 10, 0, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(),
            factory);/*from   w  w w.  j  av a2 s  .com*/
    e.prestartAllCoreThreads();

    List<Future<?>> payloadResults = new ArrayList<Future<?>>();

    long startTime = System.nanoTime();

    //create load
    for (int i = 0; i < NOF_JOBS; ++i) {
        Future<?> f = e.submit(new Payload());
        payloadResults.add(f);
    }

    //wait for it all to finish
    for (Future<?> f : payloadResults) {
        f.get();
    }

    long endTime = System.nanoTime();

    long time = endTime - startTime;
    LOG.info("MAX Multithreaded test took " + (time / 1000.0 / 1000.0) + "ms");

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long cpuTime = 0;
    for (Thread t : factory.createdThreads) {
        long threadCpuTime = threadBean.getThreadCpuTime(t.getId());
        LOG.info(t.getName() + ": " + threadCpuTime + "ns");
        cpuTime += threadCpuTime;
    }

    float actualUsage = (float) cpuTime / time;

    LOG.info("MAX Multithreaded overall usage: " + actualUsage);
}

From source file:metlos.executors.batch.BatchCpuThrottlingExecutorTest.java

@Test
public void cpuUsageRoughlyAdheredTo_SingleThreaded() throws Exception {
    NamingThreadFactory factory = new NamingThreadFactory();

    float expectedCpuUsage = MAX_USAGE;

    BatchCpuThrottlingExecutor e = getExecutor(1, expectedCpuUsage, factory);

    List<Future<?>> payloadResults = new ArrayList<Future<?>>();

    long startTime = System.nanoTime();

    //create load
    for (int i = 0; i < NOF_JOBS; ++i) {
        Future<?> f = e.submit(new Payload());
        payloadResults.add(f);//from  ww w.  j a  v  a2s . c  o  m
    }

    //wait for it all to finish
    for (Future<?> f : payloadResults) {
        f.get();
    }

    long endTime = System.nanoTime();

    long time = endTime - startTime;
    LOG.info("Singlethreaded test took " + (time / 1000.0 / 1000.0) + "ms");

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long cpuTime = 0;
    for (Thread t : factory.createdThreads) {
        long threadCpuTime = threadBean.getThreadCpuTime(t.getId());
        LOG.info(t.getName() + ": " + threadCpuTime + "ns");
        cpuTime += threadCpuTime;
    }

    float actualUsage = (float) cpuTime / time;

    LOG.info("Singlethreaded overall usage: " + actualUsage);

    //this CPU throttling stuff might not be too precise, so let's fail only on huge difference.
    float min = expectedCpuUsage * .5f;
    float max = expectedCpuUsage * 1.5f;

    Assert.assertTrue(min < actualUsage && actualUsage < max, "Actual CPU usage out of expected range: (" + min
            + ", " + expectedCpuUsage + ", " + max + ") != " + actualUsage);
}

From source file:metlos.executors.batch.BatchCpuThrottlingExecutorTest.java

@Test
public void cpuUsageRoughlyAdheredTo_MultiThreaded() throws Exception {
    NamingThreadFactory factory = new NamingThreadFactory();

    float expectedCpuUsage = MAX_USAGE;

    BatchCpuThrottlingExecutor e = getExecutor(10, expectedCpuUsage, factory);

    List<Future<?>> payloadResults = new ArrayList<Future<?>>();

    long startTime = System.nanoTime();

    //create load
    for (int i = 0; i < NOF_JOBS; ++i) {
        Future<?> f = e.submit(new Payload());
        payloadResults.add(f);//ww  w .j a  va  2s  . co m
    }

    //wait for it all to finish
    for (Future<?> f : payloadResults) {
        f.get();
    }

    long endTime = System.nanoTime();

    long time = endTime - startTime;
    LOG.info("Multithreaded test took " + (time / 1000.0 / 1000.0) + "ms");

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long cpuTime = 0;
    for (Thread t : factory.createdThreads) {
        long threadCpuTime = threadBean.getThreadCpuTime(t.getId());
        LOG.info(t.getName() + ": " + threadCpuTime + "ns");
        cpuTime += threadCpuTime;
    }

    float actualUsage = (float) cpuTime / time;

    LOG.info("Multithreaded overall usage: " + actualUsage);

    //this CPU throttling stuff might not be too precise, so let's fail only on huge difference.
    float min = expectedCpuUsage * .5f;
    float max = expectedCpuUsage * 1.5f;

    Assert.assertTrue(min < actualUsage && actualUsage < max, "Actual CPU usage out of expected range: (" + min
            + ", " + expectedCpuUsage + ", " + max + ") != " + actualUsage);
}