Skip to content

Instantly share code, notes, and snippets.

void test(String[] args) throws Throwable {
/*
* Prepare
*/
ThreadPoolExecutor tpe = prepareTestThreadPool(threadCount, timeoutMillis);
long t0 = System.nanoTime();
for (int i = 0; i < threadCount; i++)
tpe.submit(new Runnable() { public void run() {}});
void shouldRemoveThreadsAfterCoreThreadTimeoutPeriod() throws Throwable {
ThreadPoolExecutor tpe = prepareTestThreadPool(threadCount, timeoutMillis);
long t0 = System.nanoTime();
for (int i = 0; i < threadCount; i++)
tpe.submit(new Runnable() { public void run() {}});
int count = countExecutorThreads();
if (millisElapsedSince(t0) < timeoutMillis)
assertEquals(count, threadCount);
void shouldRemoveThreadsAfterCoreThreadTimeoutPeriod() throws Throwable {
ThreadPoolExecutor tpe = prepareTestThreadPool(threadCount, timeoutMillis);
long t0 = System.nanoTime();
for (int i = 0; i < threadCount; i++)
tpe.submit(new Runnable() { public void run() {}});
int count = countExecutorThreads();
if (millisElapsedSince(t0) < timeoutMillis)
assertEquals(count, threadCount);
void test(String[] args) throws Throwable {
ThreadPoolExecutor tpe = prepareTestThreadPool(threadCount, timeoutMillis);
long t0 = System.nanoTime();
for (int i = 0; i < threadCount; i++)
tpe.submit(new Runnable() { public void run() {}});
int count = countExecutorThreads();
if (millisElapsedSince(t0) < timeoutMillis)
equal(count, threadCount);
import java.util.concurrent.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
public class CoreThreadTimeOut {
final int threadPoolSize = 10;
final int timeoutMillis = 30;
import java.util.concurrent.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
public class CoreThreadTimeOut {
final int threadCount = 10;
final int timeoutMillis = 30;
import java.util.concurrent.*;
public class CoreThreadTimeOut {
static class IdentifiableThreadFactory implements ThreadFactory {
static ThreadFactory defaultThreadFactory
= Executors.defaultThreadFactory();
public Thread newThread(Runnable r) {
Thread t = defaultThreadFactory.newThread(r);
import java.util.concurrent.*;
public class CoreThreadTimeOut {
static class IdentifiableThreadFactory implements ThreadFactory {
static ThreadFactory defaultThreadFactory
= Executors.defaultThreadFactory();
public Thread newThread(Runnable r) {
Thread t = defaultThreadFactory.newThread(r);
class OrderPlacedEvent {
private Order order;
}
class ShopSellerService {
@Inject
private EventBus eventBus;
public void sell(Order order) {
class OrderPlacedEvent {
private Order order;
}
class ShopSellerService {
@Inject
private EventBus eventBus;
public void sell(Order order) {