/** * Initializes the specified thread. This method is called by * {@link #newThread(Runnable)} after a new thread has been obtained from * the wrapped thread factory. It initializes the thread according to the * options set for this factory. * * @param thread the thread to be initialized */ private void initializeThread(final Thread thread) { if (getNamingPattern() != null) { final Long count = Long.valueOf(threadCounter.incrementAndGet()); thread.setName(String.format(getNamingPattern(), count)); } if (getUncaughtExceptionHandler() != null) { thread.setUncaughtExceptionHandler(getUncaughtExceptionHandler()); } if (getPriority() != null) { thread.setPriority(getPriority().intValue()); } if (getDaemonFlag() != null) { thread.setDaemon(getDaemonFlag().booleanValue()); } }
/** * Creates a new thread. This implementation delegates to the wrapped * factory for creating the thread. Then, on the newly created thread the * corresponding configuration options are set. * * @param runnable the {@code Runnable} to be executed by the new thread * @return the newly created thread */ @Override public Thread newThread(final Runnable runnable) { final Thread thread = getWrappedFactory().newThread(runnable); initializeThread(thread); return thread; }
/** * Creates a new {@code BasicThreadFactory} with all configuration * options that have been specified by calling methods on this builder. * After creating the factory {@link #reset()} is called. * * @return the new {@code BasicThreadFactory} */ @Override public BasicThreadFactory build() { final BasicThreadFactory factory = new BasicThreadFactory(this); reset(); return factory; } }
/** * Tests the reset() method of the builder. */ @Test public void testBuilderReset() { final ThreadFactory wrappedFactory = EasyMock.createMock(ThreadFactory.class); final Thread.UncaughtExceptionHandler exHandler = EasyMock .createMock(Thread.UncaughtExceptionHandler.class); EasyMock.replay(wrappedFactory, exHandler); builder.namingPattern(PATTERN).daemon(true).priority( Thread.MAX_PRIORITY).uncaughtExceptionHandler(exHandler) .wrappedFactory(wrappedFactory); builder.reset(); final BasicThreadFactory factory = builder.build(); checkFactoryDefaults(factory); assertNotSame("Wrapped factory not reset", wrappedFactory, factory .getWrappedFactory()); EasyMock.verify(wrappedFactory, exHandler); }
/** * Tests the default options of a thread factory. * * @param factory the factory to be checked */ private void checkFactoryDefaults(final BasicThreadFactory factory) { assertNull("Got a naming pattern", factory.getNamingPattern()); assertNull("Got an exception handler", factory .getUncaughtExceptionHandler()); assertNull("Got a priority", factory.getPriority()); assertNull("Got a daemon flag", factory.getDaemonFlag()); assertNotNull("No wrapped factory", factory.getWrappedFactory()); }
/** * Creates a new thread. This implementation delegates to the wrapped * factory for creating the thread. Then, on the newly created thread the * corresponding configuration options are set. * * @param runnable the {@code Runnable} to be executed by the new thread * @return the newly created thread */ @Override public Thread newThread(final Runnable runnable) { final Thread thread = getWrappedFactory().newThread(runnable); initializeThread(thread); return thread; }
/** * Creates a new {@code BasicThreadFactory} with all configuration * options that have been specified by calling methods on this builder. * After creating the factory {@link #reset()} is called. * * @return the new {@code BasicThreadFactory} */ @Override public BasicThreadFactory build() { final BasicThreadFactory factory = new BasicThreadFactory(this); reset(); return factory; } }
/** * Initializes the specified thread. This method is called by * {@link #newThread(Runnable)} after a new thread has been obtained from * the wrapped thread factory. It initializes the thread according to the * options set for this factory. * * @param thread the thread to be initialized */ private void initializeThread(final Thread thread) { if (getNamingPattern() != null) { final Long count = Long.valueOf(threadCounter.incrementAndGet()); thread.setName(String.format(getNamingPattern(), count)); } if (getUncaughtExceptionHandler() != null) { thread.setUncaughtExceptionHandler(getUncaughtExceptionHandler()); } if (getPriority() != null) { thread.setPriority(getPriority().intValue()); } if (getDaemonFlag() != null) { thread.setDaemon(getDaemonFlag().booleanValue()); } }
/** * Creates a new thread. This implementation delegates to the wrapped * factory for creating the thread. Then, on the newly created thread the * corresponding configuration options are set. * * @param runnable the {@code Runnable} to be executed by the new thread * @return the newly created thread */ @Override public Thread newThread(final Runnable runnable) { final Thread thread = getWrappedFactory().newThread(runnable); initializeThread(thread); return thread; }
/** * Creates a new {@code BasicThreadFactory} with all configuration * options that have been specified by calling methods on this builder. * After creating the factory {@link #reset()} is called. * * @return the new {@code BasicThreadFactory} */ @Override public BasicThreadFactory build() { final BasicThreadFactory factory = new BasicThreadFactory(this); reset(); return factory; } }
/** * Initializes the specified thread. This method is called by * {@link #newThread(Runnable)} after a new thread has been obtained from * the wrapped thread factory. It initializes the thread according to the * options set for this factory. * * @param thread the thread to be initialized */ private void initializeThread(final Thread thread) { if (getNamingPattern() != null) { final Long count = Long.valueOf(threadCounter.incrementAndGet()); thread.setName(String.format(getNamingPattern(), count)); } if (getUncaughtExceptionHandler() != null) { thread.setUncaughtExceptionHandler(getUncaughtExceptionHandler()); } if (getPriority() != null) { thread.setPriority(getPriority().intValue()); } if (getDaemonFlag() != null) { thread.setDaemon(getDaemonFlag().booleanValue()); } }
/** * Creates a new thread. This implementation delegates to the wrapped * factory for creating the thread. Then, on the newly created thread the * corresponding configuration options are set. * * @param runnable the {@code Runnable} to be executed by the new thread * @return the newly created thread */ @Override public Thread newThread(final Runnable runnable) { final Thread thread = getWrappedFactory().newThread(runnable); initializeThread(thread); return thread; }
/** * Creates a new {@code BasicThreadFactory} with all configuration * options that have been specified by calling methods on this builder. * After creating the factory {@link #reset()} is called. * * @return the new {@code BasicThreadFactory} */ @Override public BasicThreadFactory build() { final BasicThreadFactory factory = new BasicThreadFactory(this); reset(); return factory; } }
/** * Initializes the specified thread. This method is called by * {@link #newThread(Runnable)} after a new thread has been obtained from * the wrapped thread factory. It initializes the thread according to the * options set for this factory. * * @param thread the thread to be initialized */ private void initializeThread(final Thread thread) { if (getNamingPattern() != null) { final Long count = Long.valueOf(threadCounter.incrementAndGet()); thread.setName(String.format(getNamingPattern(), count)); } if (getUncaughtExceptionHandler() != null) { thread.setUncaughtExceptionHandler(getUncaughtExceptionHandler()); } if (getPriority() != null) { thread.setPriority(getPriority().intValue()); } if (getDaemonFlag() != null) { thread.setDaemon(getDaemonFlag().booleanValue()); } }