All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.qatools.mongodb.util.ThreadUtil Maven / Gradle / Ivy

package ru.qatools.mongodb.util;

import static java.lang.Thread.currentThread;
import static java.lang.management.ManagementFactory.getRuntimeMXBean;

/**
 * Utility class to manipulate and query thread id
 */
public final class ThreadUtil {

    private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();

    private ThreadUtil() {
    }

    /**
     * Get the thread id
     *
     * @return the thread id
     */
    public static String threadId() {
        final Long threadId = THREAD_LOCAL.get();
        if (threadId != null) {
            return getRuntimeMXBean().getName() + "-" + threadId;
        }
        return getRuntimeMXBean().getName() + "-" + currentThread().getId();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy