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

com.fillumina.performance.producer.timer.ThreadLocalRunnable Maven / Gradle / Ivy

Go to download

Configurable tool to easily compare performances of different code snippets and to take performance telemetry of a running application.

The newest version!
package com.fillumina.performance.producer.timer;

/**
 * Allows to use a local object in each thread (useful to keep track
 * of thread usage).
 *
 * @author Francesco Illuminati
 */
public abstract class ThreadLocalRunnable implements Runnable {

    private final ThreadLocal threadLocal = new ThreadLocal<>();

    /**
     * Creates a thread local object.
     * Note that the creation of the thread local object is counted in the
     * final time so make it fast.
     */
    protected abstract T createThreadLocalObject();

    @Override
    public void run() {
        T localObject = threadLocal.get();
        if (localObject == null) {
            localObject = createThreadLocalObject();
            threadLocal.set(localObject);
        }
        run(localObject);
    }

    public abstract void run(final T localObject);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy