de.dagere.kopeme.TimeBoundedExecution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kopeme-core Show documentation
Show all versions of kopeme-core Show documentation
KoPeMe performance testing core
package de.dagere.kopeme;
import java.lang.Thread.UncaughtExceptionHandler;
public class TimeBoundedExecution {
private Thread mainThread;
private int timeout;
private Throwable testError;
public TimeBoundedExecution(Thread thread, int timeout) {
this.mainThread = thread;
this.timeout = timeout;
}
public void execute() throws Throwable {
mainThread.start();
mainThread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread arg0, Throwable arg1) {
testError = arg1;
}
});
mainThread.join(timeout);
if (mainThread.isAlive()) {
mainThread.interrupt();
}
if (testError != null)
throw testError;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy