![JAR search and dependency download from the Maven repository](/logo.png)
com.fillumina.performance.producer.timer.ThreadLocalRunnable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of performance-tools Show documentation
Show all versions of performance-tools Show documentation
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