org.apache.flink.shaded.guava18.com.google.common.util.concurrent.ThreadFactoryBuilder Java Examples

The following examples show how to use org.apache.flink.shaded.guava18.com.google.common.util.concurrent.ThreadFactoryBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RunnablesTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecutorService_uncaughtExceptionHandler() throws InterruptedException {
	final CountDownLatch handlerCalled = new CountDownLatch(1);
	final ThreadFactory threadFactory = new ThreadFactoryBuilder()
		.setDaemon(true)
		.setUncaughtExceptionHandler((t, e) -> handlerCalled.countDown())
		.build();
	final ExecutorService scheduledExecutorService =
		Executors.newSingleThreadExecutor(threadFactory);
	scheduledExecutorService.execute(() -> {
		throw new RuntimeException("foo");
	});
	Assert.assertTrue(
		"Expected handler to be called.",
		handlerCalled.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
}
 
Example #2
Source File: RunnablesTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduledExecutorService_uncaughtExceptionHandler() throws InterruptedException {
	final CountDownLatch handlerCalled = new CountDownLatch(1);
	final ThreadFactory threadFactory = new ThreadFactoryBuilder()
		.setDaemon(true)
		.setUncaughtExceptionHandler((t, e) -> handlerCalled.countDown())
		.build();
	final ScheduledExecutorService scheduledExecutorService =
		Executors.newSingleThreadScheduledExecutor(threadFactory);
	scheduledExecutorService.execute(() -> {
		throw new RuntimeException("foo");
	});
	Assert.assertFalse(
		"Expected handler not to be called.",
		handlerCalled.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
}
 
Example #3
Source File: RunnablesTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void testWithUncaughtExceptionHandler(Runnable runnable, Throwable expected)
	throws InterruptedException {
	final ThreadFactory threadFactory = new ThreadFactoryBuilder()
		.setDaemon(true)
		.setNameFormat("ueh-test-%d")
		.build();
	ScheduledExecutorService scheduledExecutorService =
		Executors.newSingleThreadScheduledExecutor(threadFactory);
	final AtomicReference<Thread> thread = new AtomicReference<>();
	final AtomicReference<Throwable> throwable = new AtomicReference<>();
	final CountDownLatch handlerCalled = new CountDownLatch(1);
	final Runnable guardedRunnable =
		Runnables.withUncaughtExceptionHandler(runnable, (t, e) -> {
			thread.set(t);
			throwable.set(e);
			handlerCalled.countDown();
		});
	scheduledExecutorService.execute(guardedRunnable);
	Assert.assertTrue(handlerCalled.await(100, TimeUnit.MILLISECONDS));
	Assert.assertNotNull(thread.get());
	Assert.assertNotNull(throwable.get());
	Assert.assertEquals("ueh-test-0", thread.get().getName());
	Assert.assertEquals(expected.getClass(), throwable.get().getClass());
	Assert.assertEquals("foo", throwable.get().getMessage());
}
 
Example #4
Source File: AbstractServerBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a thread pool for the query execution.
 * @return Thread pool for query execution
 */
private ExecutorService createQueryExecutor() {
	ThreadFactory threadFactory = new ThreadFactoryBuilder()
			.setDaemon(true)
			.setNameFormat("Flink " + getServerName() + " Thread %d")
			.build();
	return Executors.newFixedThreadPool(numQueryThreads, threadFactory);
}
 
Example #5
Source File: AbstractServerBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a thread pool for the query execution.
 * @return Thread pool for query execution
 */
private ExecutorService createQueryExecutor() {
	ThreadFactory threadFactory = new ThreadFactoryBuilder()
			.setDaemon(true)
			.setNameFormat("Flink " + getServerName() + " Thread %d")
			.build();
	return Executors.newFixedThreadPool(numQueryThreads, threadFactory);
}
 
Example #6
Source File: AbstractServerBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a thread pool for the query execution.
 * @return Thread pool for query execution
 */
private ExecutorService createQueryExecutor() {
	ThreadFactory threadFactory = new ThreadFactoryBuilder()
			.setDaemon(true)
			.setNameFormat("Flink " + getServerName() + " Thread %d")
			.build();
	return Executors.newFixedThreadPool(numQueryThreads, threadFactory);
}
 
Example #7
Source File: TestableKinesisDataFetcherForShardConsumerException.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected ExecutorService createShardConsumersThreadPool(final String subtaskName) {
	final ThreadFactory threadFactory =
		new ThreadFactoryBuilder().setNameFormat("KinesisShardConsumers-%d").build();
	return Executors.newSingleThreadExecutor(threadFactory);
}
 
Example #8
Source File: TestableKinesisDataFetcherForShardConsumerException.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected ExecutorService createShardConsumersThreadPool(final String subtaskName) {
	final ThreadFactory threadFactory =
		new ThreadFactoryBuilder().setNameFormat("KinesisShardConsumers-%d").build();
	return Executors.newSingleThreadExecutor(threadFactory);
}
 
Example #9
Source File: TestableKinesisDataFetcherForShardConsumerException.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected ExecutorService createShardConsumersThreadPool(final String subtaskName) {
	final ThreadFactory threadFactory =
		new ThreadFactoryBuilder().setNameFormat("KinesisShardConsumers-%d").build();
	return Executors.newSingleThreadExecutor(threadFactory);
}