public static ThreadFactory namedThreads(String pattern) {
        return new ThreadFactoryBuilder()
                .setNameFormat(pattern)
                .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on " + t.getName(), e))
                .build();
    }
@Test
    public void exceptionHandler() throws InterruptedException {
        ThreadFactory f = Tools.namedThreads("foo");
        Thread t = f.newThread(() -> {
            throw new IllegalStateException("BOOM!");
        });
        assertNotNull("thread should have exception handler", t.getUncaughtExceptionHandler());
        t.start();
        assertAfter(100, () -> assertEquals("incorrect thread state", Thread.State.TERMINATED, t.getState()));
    }