ThreadFactoryBuilder { public ThreadFactoryBuilder withPriority(@Nullable Integer priority) { if (priority != null && priority.intValue() < Thread.MIN_PRIORITY) { throw new IllegalArgumentException(String.format( "The provided priority %d is below the minimal thread priority %d", priority, Thread.MIN_PRIORITY)); } if (priority != null && priority.intValue() > Thread.MAX_PRIORITY) { throw new IllegalArgumentException(String.format( "The provided priority %d is above the maximal thread priority %d", priority, Thread.MAX_PRIORITY)); } this.priority = priority; return this; } private  ThreadFactoryBuilder(); static ThreadFactoryBuilder create(); ThreadFactoryBuilder withWrappedThreadFactory(@Nullable ThreadFactory wrappedThreadFactory); ThreadFactoryBuilder withName(@Nullable String name); ThreadFactoryBuilder withNamePrefix(@Nullable String namePrefix); ThreadFactoryBuilder withDaemonThreads(boolean daemonThreads); ThreadFactoryBuilder withUncaughtExceptionHandler(
            @Nullable UncaughtExceptionHandler uncaughtExceptionHandler); ThreadFactoryBuilder withPriority(@Nullable Integer priority); ThreadFactory build();  }
@Test public void testWithPriority() { ThreadFactory threadFactory = ThreadFactoryBuilder.create().withPriority(Thread.MIN_PRIORITY).build(); assertThat(threadFactory.newThread(TEST_RUNNABLE).getPriority(), is(Thread.MIN_PRIORITY)); threadFactory = ThreadFactoryBuilder.create().withPriority(Thread.MAX_PRIORITY).build(); assertThat(threadFactory.newThread(TEST_RUNNABLE).getPriority(), is(Thread.MAX_PRIORITY)); }