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

private static void print(String msg) {
    String name = Thread.currentThread().getName();
    System.err.println(name + ": " + msg);
}

From source file:Main.java

public static final void shutdownAndAwaitTermination(ExecutorService executorService) {
    if (executorService.isShutdown()) {
        return;/*from  ww  w  . java  2 s. c o  m*/
    }
    executorService.shutdown();
    try {
        if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
            executorService.shutdownNow();
        }
    } catch (InterruptedException ie) {
        executorService.shutdownNow();
        Thread.currentThread().interrupt();
    }
    executorService.shutdownNow();

}

From source file:Main.java

public static <V> V getUninterruptibly(Future<V> future) throws ExecutionException {
    boolean interrupted = false;
    try {/*from  w  w  w.  j  av a 2  s .  c o m*/
        while (true) {
            try {
                return future.get();
            } catch (InterruptedException e) {
                interrupted = true;
            }
        }
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }
}

From source file:Main.java

/**
 * Normal shutdown./*  ww w  .j a  v  a 2 s .  c  o  m*/
 *
 * @param pool the pool
 * @param timeout the timeout
 * @param timeUnit the time unit
 */
public static void normalShutdown(ExecutorService pool, int timeout, TimeUnit timeUnit) {
    try {
        pool.shutdownNow();
        if (!pool.awaitTermination(timeout, timeUnit)) {
            System.err.println("Pool did not terminate");
        }
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
    }
}

From source file:OnlyOneInMethod.java

public static void threadPrint(String msg) {
    String threadName = Thread.currentThread().getName();
    System.out.println(threadName + ": " + msg);
}

From source file:com.assertthat.selenium_shutterbug.utils.file.FileUtil.java

public static String getJsScript(String filePath) {
    try {//from   w  w  w.j av a2s. com
        return IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath));
    } catch (IOException e) {
        throw new UnableTakeSnapshotException("Unable to load JS script", e);
    }
}

From source file:Main.java

/**
 * Util method: getName of executing thread
 * @return invoking thread name//from ww w. j  a  v a2  s. c  om
 */
public static String getName() {
    return Thread.currentThread().getName();
}

From source file:Main.java

private static void recurse(List<Class<?>> classes, String packageName, Class<? extends Annotation> a)
        throws ClassNotFoundException {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    String path = packageName.replace('.', '/');
    URL resource = loader.getResource(path);
    if (resource != null) {
        String filePath = resource.getFile();
        if (filePath != null && new File(filePath).isDirectory()) {
            for (String file : new File(filePath).list()) {
                if (file.endsWith(".class")) {
                    String name = packageName + '.' + file.substring(0, file.indexOf(".class"));
                    Class<?> clazz = Class.forName(name);
                    if (clazz.isAnnotationPresent(a))
                        classes.add(clazz);
                } else if (new File(filePath, file).isDirectory()) {
                    recurse(classes, packageName + "." + file, a);
                }/*from   w  ww .ja va2s .  c  o  m*/
            }
        }
    }
}

From source file:Main.java

public static void e(String strFormat, Object... args) {
    if ((strFormat == null) || (strFormat.length() == 0))
        return;//from w  w w.j  av a  2s.c  o m

    String strMessage = strFormat;
    if (args.length != 0)
        strMessage = String.format(strFormat, args);

    int nLine = Thread.currentThread().getStackTrace()[3].getLineNumber();
    String strClass = Thread.currentThread().getStackTrace()[3].getClassName();
    String strMethod = Thread.currentThread().getStackTrace()[3].getMethodName();
    strClass = strClass.substring(strClass.lastIndexOf(".") + 1);

    String str = String.format("[%5d] %-50s %s", nLine, strClass + ":" + strMethod, strMessage);
    Log.e(m_strTag, str);
    write("[E]", m_strTag, str);
}

From source file:Main.java

public static void gracefulShutdown(ExecutorService pool, int shutdownTimeout, int shutdownNowTimeout,
        TimeUnit timeUnit) {//  www . j  a  v a2 s.  c  om
    pool.shutdown();

    try {
        if (!pool.awaitTermination((long) shutdownTimeout, timeUnit)) {
            pool.shutdownNow();
            if (!pool.awaitTermination((long) shutdownNowTimeout, timeUnit)) {
                System.err.println("Pool did not terminated");
            }
        }
    } catch (InterruptedException var5) {
        pool.shutdownNow();
        Thread.currentThread().interrupt();
    }

}