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 static void report(Throwable e) {

    if (e == null)
        return;/*  w  ww .j a  va2  s .c  o  m*/

    try {

        //debug(e);
        warn("reporting", Log.getStackTraceString(e));

        if (eh != null) {
            eh.uncaughtException(Thread.currentThread(), e);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:ThreadDemo.java

public void run() {

    // returns the state of this thread
    Thread.State state = Thread.currentThread().getState();
    System.out.println(Thread.currentThread().getName());
    System.out.println("state = " + state);
}

From source file:ThreadDemo.java

public void run() {
    for (int i = 1; i < 13; i++) {
        System.out.println(Thread.currentThread().getName() + "  " + i);
        try {/* w w  w . j a v a 2 s .  c  o m*/
            // thread to sleep for 1000 milliseconds
            Thread.sleep(1000);
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

From source file:Main.java

/**
 * Interrupts a given thread and tries to join it.
 *
 * @param thread            the thread to interrupt.
 * @param joinTimeoutMillis a join timeout.
 *///w w  w  .jav a  2 s  .  c om
public static void interruptAndJoin(final Thread thread, final long joinTimeoutMillis) {

    thread.interrupt();
    try {

        thread.join(joinTimeoutMillis);
    } catch (final InterruptedException ignored) {

        Thread.currentThread().interrupt();
    }
}

From source file:ThreadDemo.java

public void run() {
    for (int i = 1; i < 13; i++) {

        System.out.println(Thread.currentThread().getName() + "  " + i);
        try {/*from w  w w .j a  v a2  s.co  m*/
            // thread to sleep for 1000 milliseconds plus 500 nanoseconds
            Thread.sleep(1000, 500);
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

From source file:org.lambdamatic.elasticsearch.BaseIntegrationTest.java

protected static Client client() {
    final InputStream portsStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("ports.properties");
    if (portsStream != null) {
        final Properties properties = new Properties();
        try {/*from  ww  w  .  ja  va 2  s  .c  om*/
            properties.load(portsStream);
        } catch (IOException e) {
            fail("Failed to load port properties from file", e);
        }
        return Client.connectTo(new HttpHost("localhost", Integer.parseInt(properties.getProperty("es.9200"))));
    }
    return Client.connectTo(new HttpHost("localhost", 9200));
}

From source file:MyResource.java

synchronized void waitFor() throws Exception {
    System.out.println(Thread.currentThread().getName() + " is entering waitFor().");
    while (!ready)
        wait(10000);/*from   w  w  w .j ava2 s .  co  m*/

    System.out.println(Thread.currentThread().getName() + " resuming execution.");
}

From source file:MyResource.java

synchronized void waitFor() throws Exception {
    System.out.println(Thread.currentThread().getName() + " is entering waitFor().");
    while (!ready)
        wait();/* ww w. j  ava 2s .c om*/

    System.out.println(Thread.currentThread().getName() + " resuming execution.");
}

From source file:MyResource.java

synchronized void waitFor() throws Exception {
    System.out.println(Thread.currentThread().getName() + " is entering waitFor().");
    while (!ready)
        wait(10000, 500);// w w  w  .  j  a va2  s .  com

    System.out.println(Thread.currentThread().getName() + " resuming execution.");
}

From source file:Main.java

@Override
public void run() {
    Thread t = Thread.currentThread();
    String threadName = t.getName();
    System.out.println("Inside run() method:  " + threadName);
}