Example usage for java.lang Thread currentThread

List of usage examples for java.lang Thread currentThread

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static native Thread currentThread();

Source Link

Document

Returns a reference to the currently executing thread object.

Usage

From source file:Main.java

    public FXLifeCycleApp() {
   String name = Thread.currentThread().getName();
}

From source file:lh.api.showcase.server.config.ConfigurationUtils.java

public static synchronized XMLConfiguration getConfig() {

    XMLConfiguration config = null;//from  w  w w.  j  a v  a 2s  .c  o m
    InputStream in = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("lh/api/showcase/Showcase-settings.xml");
    if (in != null) {
        logger.info("Load configuration");
        config = new XMLConfiguration();
        try {
            config.load(in);
        } catch (ConfigurationException e) {
            logger.severe("Error occurred while opeing config file");
        } catch (Exception e) {
            logger.severe("Error occurred while opeing config file: " + e.getMessage());
            throw e;
        } finally {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
    } else {
        logger.info("NO configuration file found");
    }
    return config;
}

From source file:Main.java

/**
 * Get the top thread group of this JVM.
 *
 * @return the top thread group//from w w  w . ja  va 2  s .co m
 */
public static final ThreadGroup topGroup() {
    ThreadGroup topGroup = Thread.currentThread().getThreadGroup();
    ThreadGroup pareGroup = topGroup.getParent();
    // Iterate through the group link.
    while (pareGroup != null) {
        topGroup = pareGroup;
        pareGroup = pareGroup.getParent();
    }
    return topGroup;
}

From source file:Main.java

/**
 * Return the system thread group (sometimes also referred as "root thread group").
 *
 * @return the system thread group//from   ww w  .  j a v  a2  s  .  co m
 * @throws  SecurityException  if the current thread cannot modify
 *          thread groups from this thread's thread group up to the system thread group
 */
public static ThreadGroup getSystemThreadGroup() {
    ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
    while (threadGroup.getParent() != null) {
        threadGroup = threadGroup.getParent();
    }
    return threadGroup;
}

From source file:Main.java

public static String getThreadStack() {
    return getStackTrace(Thread.currentThread().getStackTrace());
}

From source file:Main.java

public static void logMessage(Throwable t) {
    logMessage(Thread.currentThread().hashCode(), getStackTrace(t));
}

From source file:TwoThread.java

public void printMsg() {
    Thread t = Thread.currentThread();

    if (t == creatorThread) {
        System.out.println("Creator thread");
    } else if (t == this) {
        System.out.println("New thread");
    } else {//from  ww w.  ja  v  a 2s. com
        System.out.println("Unexpected threads!");
    }
}

From source file:com.redhat.red.build.koji.testutil.TestResourceUtils.java

public static String readTestResourceString(String resource) throws IOException {
    try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) {
        return IOUtils.toString(in);
    }//from  ww w.  j  a va 2  s . co m
}

From source file:RunnableThread.java

public String toString() {
    return "#" + Thread.currentThread().getName() + ": " + countDown;
}

From source file:Main.java

public static boolean stop(ExecutorService executorService, int waitBeforeTerminateSecs, Logger logger)
/*     */ {/*  w w w .  ja va  2  s.co m*/
    /*  53 */int waitMillis = Math.max(1000, 1000 * waitBeforeTerminateSecs);
    /*     */
    /*     */
    /*  56 */executorService.shutdown();
    /*     */
    /*     */
    /*  59 */boolean stopped = false;
    /*  60 */while ((waitMillis > 0) && (!stopped)) {
        /*  61 */long startMillis = System.currentTimeMillis();
        /*     */try {
            /*  63 */logger.debug("Waiting for thread pool to stop");
            /*  64 */stopped = executorService.awaitTermination(waitMillis, TimeUnit.MILLISECONDS);
            /*     */} catch (InterruptedException e) {
            /*  66 */logger.debug("Thread was interrupted while it was waiting for thread pool to stop", e);
            /*  67 */Thread.currentThread().interrupt();
            /*  68 */break;
            /*     */}
        /*  70 */waitMillis = (int) (waitMillis - (System.currentTimeMillis() - startMillis));
        /*     */}
    /*     */
    /*  73 */if (!executorService.isTerminated()) {
        /*  74 */logger.warn("Thread pool will be forcibly stopped now if it has not already stopped");
        /*  75 */executorService.shutdownNow();
        /*     */try {
            /*  77 */stopped = executorService.awaitTermination(waitBeforeTerminateSecs, TimeUnit.SECONDS);
            /*     */}
        /*     */catch (InterruptedException e) {
        }
        /*     */
        /*  81 */if (!executorService.isTerminated()) {
            /*  82 */logger.warn("Could not shutdown thread pool in [{}] seconds",
                    Integer.valueOf(waitBeforeTerminateSecs));
            /*     */}
        /*     */}
    /*     */
    /*  86 */return stopped;
    /*     */}