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:ca.uviccscu.lp.server.main.ShutdownListener.java

public void threadReadout() {
    l.trace("Active thread readout");
    ThreadGroup tg = Thread.currentThread().getThreadGroup();
    while (tg.getParent() != null) {
        tg = tg.getParent();/*from   ww w  .j  ava2s . c o  m*/
    }
    Thread[] threads = new Thread[tg.activeCount() + 1024];
    tg.enumerate(threads, true);
    //VERY BAD WAY TO STOP THREAD BUT NO CHOICE - need to release the file locks
    for (int i = 0; i < threads.length; i++) {
        Thread th = threads[i];
        if (th != null) {
            l.trace("Thread " + i + " : " + th.getName());

        }
    }
}

From source file:gridool.util.net.InterruptableInputStream.java

private int internalRead(final byte[] b, final int off, final int len) throws IOException {
    boolean ntraced = true;
    while (true) {
        try {/*from   w ww .ja  va 2  s.  c o  m*/
            final int n = is.read(b, off, len);
            return n;
        } catch (SocketTimeoutException e) {
            if (Thread.interrupted()) {
                throw e;
            } else {
                Thread thread = Thread.currentThread();
                if (!thread.isDaemon()) {
                    State state = thread.getState();
                    switch (state) {
                    case BLOCKED:
                    case WAITING:
                        if (LOG.isWarnEnabled()) {
                            LOG.warn("thread (" + thread.getName() + "timeout: " + thread.getState(), e);
                        }
                        throw e;
                    default:
                        if (LOG.isTraceEnabled() && ntraced) {
                            ntraced = false;
                            LOG.trace("thread (" + thread.getName() + ") timeout: " + thread.getState());
                        }
                        break;
                    }
                }
            }
        }
    }
}

From source file:com.cloud.utils.backoff.impl.ConstantTimeBackoffTest.java

/**
 * Test that wakeup will return true if the thread is waiting.
 *///from  ww w .  ja v a 2 s.  c o  m
@Test
public void wakeupExisting() throws InterruptedException {
    final ConstantTimeBackoff backoff = new ConstantTimeBackoff();
    backoff.setTimeToWait(10);
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            LOG.debug("before");
            backoff.waitBeforeRetry();
            LOG.debug("after");
        }
    });
    thread.start();
    LOG.debug("thread started");
    Thread.sleep(100);
    LOG.debug("testing wakeup");
    Assert.assertTrue(backoff.wakeup(thread.getName()));
}

From source file:io.bifroest.commons.boot.BootLoaderNG.java

/**
 * Constructs a bootloader with supplied environment. If autoSearchSystems
 * is true, the bootloader tries to load the subsystems via SearviceLoader.
 * If set to false, the subsystems must be added through the addSubsystem()-
 * method// w ww.java2 s.  co  m
 *
 * @param env A environment extented from @see Environment
 * @param autoSearchSystems if true, autoload systems, false does not load
 * any system.
 * @throws ConfigurationException
 */
public BootLoaderNG(E env, boolean autoSearchSystems) throws ConfigurationException {
    environment = env;
    loader = new ActualJSONConfigurationLoader<>(environment);
    environment.setConfigurationLoader(loader);
    this.loadConfiguration();
    registerOptionalStatusWriter(env, loader);
    if (autoSearchSystems) {
        findAvailableSubsystems();
    }
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            shutdown();
        }
    });
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            log.error("Exception in thread " + t.getName(), e);
        }
    });

    ProfilingPanic.INSTANCE.addAction(new PanicAnnouncement());
}

From source file:com.gargoylesoftware.htmlunit.SimpleWebTestCase.java

/**
 * Gets the active JavaScript threads./*from   w  w w. j av a2s.  c o  m*/
 * @return the threads
 */
protected List<Thread> getJavaScriptThreads() {
    final Thread[] threads = new Thread[Thread.activeCount() + 10];
    Thread.enumerate(threads);
    final List<Thread> jsThreads = new ArrayList<Thread>();
    for (final Thread t : threads) {
        if (t != null && t.getName().startsWith("JS executor for")) {
            jsThreads.add(t);
        }
    }

    return jsThreads;
}

From source file:com.npower.dm.setup.task.DeviceGeneratorTask.java

@Override
protected void process() throws SetupException {

    int totalThread = this.getTotalThread();
    this.getSetup().getConsole().println("Starting total thread: " + totalThread);
    try {//from   w  w w.j  a v a 2  s.  c  o m
        ThreadGroup group = new ThreadGroup(this.getClass().getName());
        List<Thread> threads = new ArrayList<Thread>();
        for (int i = 0; i < totalThread; i++) {
            TaskThread runnable = new TaskThread(this);
            Thread t = new Thread(group, runnable, "Thread#" + i);
            threads.add(t);
            t.start();
            this.getSetup().getConsole().println("Started thread: " + t.getName());
        }
        /*
        try {
          Thread.sleep(1000 * 3600 * 12);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        */
        for (Thread t : threads) {
            t.join();
        }
    } catch (InterruptedException e) {
        throw new SetupException(e.getMessage(), e);
    }

    this.getSetup().getConsole().println("All of thread finished.");
}

From source file:ThreadViewer.java

private void createPendingCellData() {
    Thread[] thread = findAllThreads();
    Object[][] cell = new Object[thread.length][columnCount];

    for (int i = 0; i < thread.length; i++) {
        Thread t = thread[i];
        Object[] rowCell = cell[i];

        rowCell[0] = new Integer(t.getPriority());
        rowCell[1] = new Boolean(t.isAlive());
        rowCell[2] = new Boolean(t.isDaemon());
        rowCell[3] = new Boolean(t.isInterrupted());
        rowCell[4] = t.getThreadGroup().getName();
        rowCell[5] = t.getName();
    }//from w ww. j  ava  2s .c  o  m

    synchronized (dataLock) {
        pendingCellData = cell;
    }
}

From source file:org.hyperic.lather.server.LatherServlet.java

private void doServiceCall(HttpServletRequest req, HttpServletResponse resp, String methName, LatherValue args,
        LatherXCoder xCoder, LatherContext ctx) throws IOException {

    final LatherDispatcher latherDispatcher = Bootstrap.getBean(LatherDispatcher.class);
    final ServiceCaller caller = new ServiceCaller(resp, xCoder, ctx, methName, args, latherDispatcher);
    final Thread currentThread = Thread.currentThread();
    final String threadName = currentThread.getName();

    try {/*w  ww .j ava2s. c  om*/
        currentThread.setName(methName + "-" + ids.getAndIncrement());
        LatherThreadMonitor.get().register(caller);
        caller.run();
        if (currentThread.isInterrupted()) {
            throw new InterruptedException();
        }
    } catch (InterruptedException exc) {
        log.warn("Interrupted while trying to execute lather method=" + methName + " from ip="
                + ctx.getCallerIP());
    } finally {
        caller.markFinished();
        currentThread.setName(threadName);
    }
}

From source file:guru.qas.martini.runtime.harness.MartiniCallable.java

@Override
public MartiniResult call() {
    LOGGER.info("executing scenario {}", martini.getId());
    Thread thread = Thread.currentThread();
    Set<String> categorizations = categories.getCategorizations(martini);

    DefaultMartiniResult result = DefaultMartiniResult.builder()
            .setThreadGroupName(thread.getThreadGroup().getName()).setThreadName(thread.getName())
            .setCategorizations(categorizations).setMartini(martini).setMartiniSuiteIdentifier(suiteIdentifier)
            .build();//from   www .  j av  a 2s  .  co m

    eventManager.publishBeforeScenario(this, result);

    try {
        Map<Step, StepImplementation> stepIndex = martini.getStepIndex();
        result.setStartTimestamp(System.currentTimeMillis());

        DefaultStepResult lastResult = null;
        for (Map.Entry<Step, StepImplementation> mapEntry : stepIndex.entrySet()) {

            Step step = mapEntry.getKey();
            eventManager.publishBeforeStep(this, result);

            StepImplementation implementation = mapEntry.getValue();
            if (null == lastResult || Status.PASSED == lastResult.getStatus()) {
                lastResult = execute(step, implementation);
            } else {
                lastResult = new DefaultStepResult(step, implementation);
                lastResult.setStatus(Status.SKIPPED);
            }
            result.add(lastResult);
            eventManager.publishAfterStep(this, result);
        }
    } finally {
        result.setEndTimestamp(System.currentTimeMillis());
        eventManager.publishAfterScenario(this, result);
    }

    return result;
}

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

private void startWaitAliveThenWaitItLives(final Thread t, final int ms) {
    t.start();/*from  www . ja v  a  2 s . c om*/
    while (!t.isAlive()) {
        // Wait
    }
    // Wait one second.
    Threads.sleep(ms);
    assertTrue("Assert " + t.getName() + " still waiting", t.isAlive());
}