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:fitnesse.FitNesseVersion.java

private static Properties getBuildProperties() {
    Properties buildProperties = new Properties();
    InputStream propertyStream = null;
    Reader propertyReader = null;
    try {//w  w w .ja  va2  s  . co m
        propertyStream = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("fitnesse/build.properties");
        propertyReader = new InputStreamReader(propertyStream);
        buildProperties.load(propertyReader);
    } catch (NullPointerException e) {
        throw new RuntimeException(
                "Could not load build.properties from the classpath.  Are you sure the jar is packaged correctly?",
                e);
    } catch (IOException e) {
        throw new RuntimeException(
                "Could not load build.properties from the classpath.  Are you sure the jar is packaged correctly?",
                e);
    } finally {
        IOUtils.closeQuietly(propertyReader);
        IOUtils.closeQuietly(propertyStream);
    }
    return buildProperties;
}

From source file:Main.java

public static void shutdown(final ExecutorService executorService) {
    executorService.shutdown();/*w  w  w . j  a  va  2s  .c o  m*/
    try {
        int timeToWait = 30;
        if (!executorService.awaitTermination(timeToWait, TimeUnit.SECONDS)) {
            List<Runnable> executionList = executorService.shutdownNow();
            for (Runnable runnable : executionList) {
                System.out.println("Trying to shutdown task: " + runnable);
            }
        }
        if (!executorService.awaitTermination(timeToWait, TimeUnit.SECONDS)) {
        }
    } catch (InterruptedException ex) {
        executorService.shutdownNow();
        Thread.currentThread().interrupt();
    }
}

From source file:Main.java

/** Sleep for timeout msecs. Returns when timeout has elapsed or thread was interrupted */
public static void sleep(long timeout) {
    try {//  ww w  . ja  va 2 s.  c  o m
        Thread.sleep(timeout);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:Main.java

public static void init(Context context) {
    mContext = context;
    mUiThread = Thread.currentThread();
}

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

/**
 * sleep, ??, ???InterruptedException.// www . j  a v a2 s. c o  m
 */
public static void sleep(long durationMillis) {
    try {
        Thread.sleep(durationMillis);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:Main.java

public static void debugWhere(String tag, String msg) {
    Log.d(tag, msg + " --- stack trace begins: ");
    StackTraceElement elements[] = Thread.currentThread().getStackTrace();
    // skip first 3 element, they are not related to the caller
    for (int i = 3, n = elements.length; i < n; ++i) {
        StackTraceElement st = elements[i];
        String message = String.format("    at %s.%s(%s:%s)", st.getClassName(), st.getMethodName(),
                st.getFileName(), st.getLineNumber());
        Log.d(tag, message);//  w  w w . j  av a 2s . c o  m
    }
    Log.d(tag, msg + " --- stack trace ends.");
}

From source file:Main.java

/**
 * //from  w  w w  . java 2s.c  o m
 * "waitTimeBool" wait for the given time.
 * 
 * @param time
 * @return true if interrupted, else false
 */
public static boolean waitTimeBool(long time) {
    synchronized (Thread.currentThread()) {
        try {
            Thread.currentThread().wait(time);
        } catch (InterruptedException e) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static boolean sleep(long milliseconds) {
    try {// w ww  .j  a  v  a 2  s.  c om
        Thread.sleep(milliseconds);
        return true;
    } catch (InterruptedException ignore) {
        Thread.currentThread().interrupt();
        return false;
    }
}

From source file:com.vico.license.util.rsa.RSAdoEncrypt.java

public static String encrypt(String source, byte[] publickey) throws Exception {

    String path = Thread.currentThread().getContextClassLoader().getResource("/").toURI().getPath();
    Key publicKey = null;/*from ww  w .java 2s .c om*/

    publicKey = (Key) ByteArrayToObj.ByteToObject(publickey);

    /** Cipher???RSA */
    Cipher cipher = Cipher.getInstance(ALGORITHM);
    cipher.init(Cipher.ENCRYPT_MODE, publicKey);
    byte[] b = source.getBytes("UTF-8");

    /** ?*/
    byte[] b1 = cipher.doFinal(b);

    String encryptedcode = Base64.encodeBase64String(b1);
    return encryptedcode;
}

From source file:Main.java

public static void sleepUninterrupted(long millis) {
    try {/*w w w  . j a  v  a2  s  .co m*/
        Thread.currentThread().sleep(millis);
    } catch (InterruptedException ex) {
        throw new AssertionError(ex);
    }
}