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:com.mycorp.SwaggerConfiguredArquillianTest.java

/**
 * Construct a deployment that will trigger the framework to initialize a default JAX-RS Application.
 *///  ww w .  j ava 2 s .  co  m
@Deployment
public static Archive createDeployment() throws Exception {
    WARArchive archive = ShrinkWrap.create(WARArchive.class, "SampleTest.war");
    archive.addClass(Resource.class);
    URL yml = Thread.currentThread().getContextClassLoader().getResource("project-defaults.yml");
    assert yml != null;
    archive.addAsResource(new File(yml.toURI()), "/project-defaults.yml");
    archive.addAllDependencies();
    return archive;
}

From source file:com.arrow.acs.ManifestUtils.java

public static Manifest readManifest(Class<?> clazz) {
    String method = "readManifest";
    String jarFile = null;/*  ww  w . ja  va  2 s .c o  m*/
    String path = clazz.getProtectionDomain().getCodeSource().getLocation().toString();
    for (String token : path.split("/")) {
        token = token.replace("!", "").toLowerCase().trim();
        if (token.endsWith(".jar")) {
            jarFile = token;
            break;
        }
    }
    LOGGER.logInfo(method, "className: %s, path: %s, jarFile: %s", clazz.getName(), path, jarFile);
    InputStream is = null;
    try {
        if (!StringUtils.isEmpty(jarFile)) {
            Enumeration<URL> enumeration = Thread.currentThread().getContextClassLoader()
                    .getResources(JarFile.MANIFEST_NAME);
            while (enumeration.hasMoreElements()) {
                URL url = enumeration.nextElement();
                for (String token : url.toString().split("/")) {
                    token = token.replace("!", "").toLowerCase();
                    if (token.equals(jarFile)) {
                        LOGGER.logInfo(method, "loading manifest from: %s", url.toString());
                        return new Manifest(is = url.openStream());
                    }
                }
            }
        } else {
            URL url = new URL(path + "/META-INF/MANIFEST.MF");
            LOGGER.logInfo(method, "loading manifest from: %s", url.toString());
            return new Manifest(is = url.openStream());
        }
    } catch (IOException e) {
    } finally {
        IOUtils.closeQuietly(is);
    }
    LOGGER.logError(method, "manifest file not found for: %s", clazz.getName());
    return null;
}

From source file:com.dtolabs.client.utils.ClientState.java

/**
 * Reset the HTTP State object for the current thread
 */// w  ww  .  j a  va 2 s .  c o  m
public synchronized static HttpState resetHttpState() {
    httpStates.remove(Thread.currentThread());
    return getHttpState();
}

From source file:edu.umn.msi.tropix.common.concurrent.impl.UncaughtExceptionHandlerUtils.java

public static void handleException(@Nullable final UncaughtExceptionHandler handler, final Throwable t) {
    final Thread currentThread = Thread.currentThread();
    UncaughtExceptionHandler eh;//ww  w. j ava 2s  .c  o m
    if (handler != null) {
        eh = handler;
    } else {
        eh = currentThread.getUncaughtExceptionHandler();
    }
    try {
        eh.uncaughtException(currentThread, t);
    } catch (final Throwable exceptionThrowable) {
        ExceptionUtils.logQuietly(LOG, exceptionThrowable);
    }
}

From source file:Main.java

public static void reallySleep(long millis, int nanos) {
    boolean interrupted = false;
    try {//from  w ww . ja  v a  2s.  co m
        long millisLeft = millis;
        while (millisLeft > 0 || nanos > 0) {
            long start = System.currentTimeMillis();
            try {
                Thread.sleep(millisLeft, nanos);
            } catch (InterruptedException e) {
                interrupted = true;
            }
            millisLeft -= System.currentTimeMillis() - start;
            nanos = 0; // Not using System.nanoTime() since it is 1.5 specific
        }
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }
}

From source file:Main.java

/**
 * Causes the current Thread to sleep for the specified number of milliseconds.  If the current Thread is interrupted
 * during sleep, the interrupt flag on the current Thread will remain set and the duration, in milliseconds, of completed sleep is returned.
 * <p/>// www . j a  va2s. c  o  m
 * @param milliseconds an integer value specifying the number of milliseconds the current Thread should sleep.
 * @return a long value indicating duration in milliseconds of completed sleep by the current Thread.
 * @see java.lang.System#nanoTime()
 * @see java.lang.Thread#sleep(long)
 */
public static long sleep(final long milliseconds) {
    final long t0 = System.nanoTime();

    try {
        Thread.sleep(milliseconds);
    } catch (InterruptedException ignore) {
        Thread.currentThread().interrupt();
    }

    return (System.nanoTime() - t0) / 1000;
}

From source file:ReflectionHelper.java

public static Class<?> classForName(String name, Class<?> caller) throws ClassNotFoundException {
    try {//from   w w w  . j ava 2 s . c  o  m
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        if (contextClassLoader != null) {
            return contextClassLoader.loadClass(name);
        }
    } catch (Throwable e) {
        // ignore
    }
    return Class.forName(name, true, caller.getClassLoader());
}

From source file:com.sap.prd.mobile.ios.mios.ModuleBuildTest.java

@BeforeClass
public static void __setup() throws Exception {
    dynamicVersion = "1.0." + String.valueOf(System.currentTimeMillis());
    testName = ModuleBuildTest.class.getName() + File.separator
            + Thread.currentThread().getStackTrace()[1].getMethodName();

    remoteRepositoryDirectory = getRemoteRepositoryDirectory(ModuleBuildTest.class.getName());

    prepareRemoteRepository(remoteRepositoryDirectory);

    Properties pomReplacements = new Properties();
    pomReplacements.setProperty(PROP_NAME_DEPLOY_REPO_DIR, remoteRepositoryDirectory.getAbsolutePath());
    pomReplacements.setProperty(PROP_NAME_DYNAMIC_VERSION, dynamicVersion);

    test(testName, new File(getTestRootDirectory(), "moduleBuild"), "deploy", THE_EMPTY_LIST, THE_EMPTY_MAP,
            pomReplacements, new NullProjectModifier());

    testExecutionDirectoryLibrary = getTestExecutionDirectory(testName, "moduleBuild/MyLibrary");
    testExecutionDirectoryApplication = getTestExecutionDirectory(testName, "moduleBuild/MyApp");

}

From source file:com.sap.prd.mobile.ios.mios.VersionWithAppAsSnapshotTest.java

@BeforeClass
public static void __setup() throws Exception {

    dynamicVersion = "1.0." + String.valueOf(System.currentTimeMillis());
    testName = VersionWithAppAsSnapshotTest.class.getName() + File.separator
            + Thread.currentThread().getStackTrace()[1].getMethodName();

    remoteRepositoryDirectory = getRemoteRepositoryDirectory(VersionWithAppAsSnapshotTest.class.getName());

    prepareRemoteRepository(remoteRepositoryDirectory);

    Properties pomReplacements = new Properties();
    pomReplacements.setProperty(PROP_NAME_DEPLOY_REPO_DIR, remoteRepositoryDirectory.getAbsolutePath());
    pomReplacements.setProperty(PROP_NAME_DYNAMIC_VERSION, dynamicVersion);

    test(testName, new File(getTestRootDirectory(), "straight-forward/MyLibrary"), "deploy", THE_EMPTY_LIST,
            THE_EMPTY_MAP, pomReplacements, new NullProjectModifier());

    appVerifier = test(testName, new File(getTestRootDirectory(), "straight-forward/MyApp"), "deploy",
            THE_EMPTY_LIST, null, pomReplacements, new AppendSnapshotToProjectVersionProjectModifier());

    appTestBaseDir = new File(appVerifier.getBasedir());
}