![JAR search and dependency download from the Maven repository](/logo.png)
link.jfire.testsupport.rule.MutiThreadStatement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfire-testsupport Show documentation
Show all versions of jfire-testsupport Show documentation
Testsupport is test of jfire system support framework
The newest version!
package link.jfire.testsupport.rule;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.junit.runners.model.Statement;
public class MutiThreadStatement extends Statement
{
private int repaetTimes;
private int threadNums;
private Statement statement;
private ExecutorService pool;
public MutiThreadStatement(int repaetTimes, int threadNums, Statement statement)
{
this.repaetTimes = repaetTimes;
this.threadNums = threadNums;
this.statement = statement;
pool = Executors.newFixedThreadPool(threadNums);
}
public void evaluate() throws Throwable
{
List> set = new LinkedList<>();
for (int i = 0; i < threadNums; i++)
{
Future future = pool.submit(new Callable() {
public Void call() throws Exception
{
try
{
for (int j = 0; j < repaetTimes; j++)
{
statement.evaluate();
}
return null;
}
catch (Throwable e)
{
throw new RuntimeException(e);
}
}
});
set.add(future);
}
pool.shutdown();
for (Future each : set)
{
each.get();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy