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

public void run() {
    if (Thread.currentThread() != internalThread) {
        throw new RuntimeException("only the internal " + "thread is allowed to invoke run()");
    }/*w w  w .  j a v  a2 s  .  c  o m*/

    while (noStopRequested) {
        System.out.println("in run() - still going...");

        try {
            Thread.sleep(700);
        } catch (InterruptedException x) {
            Thread.currentThread().interrupt();
        }
    }
}

From source file:me.j360.dubbo.modules.util.concurrent.ThreadUtil.java

/**
 * ???InterruptedException????.
 */
public static void handleInterruptedException() {
    Thread.currentThread().interrupt();
}

From source file:Main.java

@Override
public void init() {
    String name = Thread.currentThread().getName();
    System.out.println("init() method: " + name);
}

From source file:Main.java

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

From source file:Main.java

/**
 * Check the given Throwable and recursively his cause to in order to find
 * an InterruptedException instance. If found, the exception is rethrown and
 * the current Thread is interrupted./*from  w ww.  ja  v a2  s  . c om*/
 * 
 * @param thw
 * @throws InterruptedException
 */
public static void checkInterrupted(Throwable thw) throws InterruptedException {
    while (thw != null) {
        if (thw instanceof InterruptedException) {
            Thread.currentThread().interrupt();
            throw (InterruptedException) thw;
        }
        thw = thw.getCause();
    }
}

From source file:com.dx.ss.plugins.ptree.utils.ClassloaderUtility.java

public static ClassLoader getCustomClassloader(String classpathEntry) {
    File file = null;/*from w w  w .  j  av  a  2s. co m*/
    try {
        if (StringUtils.isNotBlank(classpathEntry)) {
            file = new File(classpathEntry);
            if (file.exists()) {
                ClassLoader parent = Thread.currentThread().getContextClassLoader();
                URLClassLoader ucl = new URLClassLoader(new URL[] { file.toURI().toURL() }, parent);
                return ucl;
            }
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public void run() {

    Thread t = Thread.currentThread();
    System.out.print(t.getName());
    System.out.println(", status = " + t.isAlive());
}

From source file:Main.java

/**
 * Utility to essentially do Class forName and allow configurable
 * Classloaders./* w ww.  j a v  a  2 s . c  o m*/
 * <p>The initial implementation makes use of the context classloader for
 * the current thread.
 * @param className The class to create
 * @return The class if it is safe or null otherwise.
 * @throws ClassNotFoundException If <code>className</code> is not valid
 */
public static Class<?> classForName(String className) throws ClassNotFoundException {
    // Class.forName(className);
    return Thread.currentThread().getContextClassLoader().loadClass(className);
}

From source file:Main.java

@Override
 public void init() {
     String name = Thread.currentThread().getName();
     System.out.println("init() method: " + name);
 }

From source file:school.service.ImportService.java

protected static String load(String cqlFile) {
    StringBuilder sb = new StringBuilder();
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(cqlFile)));
    String line;/*  w  ww  .  j av a 2s.  co  m*/
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line);
            sb.append(" ");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return sb.toString();
}