Created
November 7, 2014 00:42
-
-
Save eliasnogueira/3d0e978404f54054bdf3 to your computer and use it in GitHub Desktop.
Exemplo de classe para execução de teste em paralelo com JUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.TimeUnit; | |
import org.junit.runners.Parameterized; | |
import org.junit.runners.model.RunnerScheduler; | |
public class Paralelo extends Parameterized { | |
public Paralelo(Class<?> arg0) throws Throwable { | |
super(arg0); | |
setScheduler(new RunnerScheduler() { | |
private final ExecutorService service = Executors.newFixedThreadPool(8); | |
public void schedule(Runnable childStatement) { | |
service.submit(childStatement); | |
} | |
public void finished() { | |
try { | |
service.shutdown(); | |
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); | |
} catch (InterruptedException e) { | |
e.printStackTrace(System.err); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment