Skip to content

Commit 18d3020

Browse files
committed
Javadoc
- Better docs for BasicThreadFactory's naming pattern - Use {@code}
1 parent 6901280 commit 18d3020

1 file changed

Lines changed: 57 additions & 38 deletions

File tree

src/main/java/org/apache/commons/lang3/concurrent/BasicThreadFactory.java

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ public static class Builder implements org.apache.commons.lang3.builder.Builder<
108108
/** The uncaught exception handler. */
109109
private Thread.UncaughtExceptionHandler exceptionHandler;
110110

111-
/** The naming pattern. */
111+
/**
112+
* The naming pattern for newly created threads.
113+
* <p>
114+
* The naming pattern is a {@link String#format(String, Object...) format string} that expects a single argument. This argument is the number of the
115+
* thread to be created. For instance, if the naming pattern is {@code "MyThread-%d"}, the first thread created by this factory will be named
116+
* {@code "MyThread-1"}, the second one {@code "MyThread-2"} and so on.
117+
* </p>
118+
*/
112119
private String namingPattern;
113120

114121
/** The priority. */
@@ -132,7 +139,7 @@ public Builder() {
132139
* options that have been specified by calling methods on this builder.
133140
* After creating the factory {@link #reset()} is called.
134141
*
135-
* @return the new {@link BasicThreadFactory}
142+
* @return the new {@link BasicThreadFactory}.
136143
*/
137144
@Override
138145
public BasicThreadFactory build() {
@@ -144,7 +151,7 @@ public BasicThreadFactory build() {
144151
/**
145152
* Sets the daemon flag for the new {@link BasicThreadFactory} to {@code true} causing a new thread factory to create daemon threads.
146153
*
147-
* @return a reference to this {@link Builder}
154+
* @return a reference to this {@link Builder}.
148155
* @since 3.18.0
149156
*/
150157
public Builder daemon() {
@@ -156,8 +163,8 @@ public Builder daemon() {
156163
* flag is set to <strong>true</strong> the new thread factory will create daemon
157164
* threads.
158165
*
159-
* @param daemon the value of the daemon flag
160-
* @return a reference to this {@link Builder}
166+
* @param daemon the value of the daemon flag.
167+
* @return a reference to this {@link Builder}.
161168
*/
162169
public Builder daemon(final boolean daemon) {
163170
this.daemon = Boolean.valueOf(daemon);
@@ -167,10 +174,15 @@ public Builder daemon(final boolean daemon) {
167174
/**
168175
* Sets the naming pattern to be used by the new {@code
169176
* BasicThreadFactory}.
177+
* <p>
178+
* The naming pattern is a {@link String#format(String, Object...) format string} that expects a single argument. This argument is the number of the
179+
* thread to be created. For instance, if the naming pattern is {@code "MyThread-%d"}, the first thread created by this factory will be named
180+
* {@code "MyThread-1"}, the second one {@code "MyThread-2"} and so on.
181+
* </p>
170182
*
171-
* @param namingPattern the naming pattern (must not be <strong>null</strong>)
172-
* @return a reference to this {@link Builder}
173-
* @throws NullPointerException if the naming pattern is <strong>null</strong>
183+
* @param namingPattern the naming pattern (must not be {@code null}).
184+
* @return a reference to this {@link Builder}.
185+
* @throws NullPointerException if the naming pattern is {@code null}.
174186
*/
175187
public Builder namingPattern(final String namingPattern) {
176188
this.namingPattern = Objects.requireNonNull(namingPattern, "pattern");
@@ -181,8 +193,8 @@ public Builder namingPattern(final String namingPattern) {
181193
* Sets the priority for the threads created by the new {@code
182194
* BasicThreadFactory}.
183195
*
184-
* @param priority the priority
185-
* @return a reference to this {@link Builder}
196+
* @param priority the priority.
197+
* @return a reference to this {@link Builder}.
186198
*/
187199
public Builder priority(final int priority) {
188200
this.priority = Integer.valueOf(priority);
@@ -204,13 +216,11 @@ public void reset() {
204216
}
205217

206218
/**
207-
* Sets the uncaught exception handler for the threads created by the
208-
* new {@link BasicThreadFactory}.
219+
* Sets the uncaught exception handler for the threads created by the new {@link BasicThreadFactory}.
209220
*
210-
* @param exceptionHandler the {@link UncaughtExceptionHandler} (must not be
211-
* <strong>null</strong>)
212-
* @return a reference to this {@link Builder}
213-
* @throws NullPointerException if the exception handler is <strong>null</strong>
221+
* @param exceptionHandler the {@link UncaughtExceptionHandler} (must not be {@code null}).
222+
* @return a reference to this {@link Builder}.
223+
* @throws NullPointerException if the exception handler is {@code null}.
214224
*/
215225
public Builder uncaughtExceptionHandler(
216226
final Thread.UncaughtExceptionHandler exceptionHandler) {
@@ -222,11 +232,9 @@ public Builder uncaughtExceptionHandler(
222232
* Sets the {@link ThreadFactory} to be wrapped by the new {@code
223233
* BasicThreadFactory}.
224234
*
225-
* @param factory the wrapped {@link ThreadFactory} (must not be
226-
* <strong>null</strong>)
235+
* @param factory the wrapped {@link ThreadFactory} (must not be {@code null})
227236
* @return a reference to this {@link Builder}
228-
* @throws NullPointerException if the passed in {@link ThreadFactory}
229-
* is <strong>null</strong>
237+
* @throws NullPointerException if the passed in {@link ThreadFactory} is {@code null}
230238
*/
231239
public Builder wrappedFactory(final ThreadFactory factory) {
232240
this.factory = Objects.requireNonNull(factory, "factory");
@@ -247,13 +255,20 @@ public static Builder builder() {
247255
/** A counter for the threads created by this factory. */
248256
private final AtomicLong threadCounter;
249257

250-
/** Stores the wrapped factory. */
258+
/** The wrapped factory. */
251259
private final ThreadFactory wrappedFactory;
252260

253-
/** Stores the uncaught exception handler. */
261+
/** The uncaught exception handler. */
254262
private final Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
255263

256-
/** Stores the naming pattern for newly created threads. */
264+
/**
265+
* The naming pattern for newly created threads.
266+
* <p>
267+
* The naming pattern is a {@link String#format(String, Object...) format string} that expects a single argument. This argument is the number of the thread
268+
* to be created. For instance, if the naming pattern is {@code "MyThread-%d"}, the first thread created by this factory will be named {@code "MyThread-1"},
269+
* the second one {@code "MyThread-2"} and so on.
270+
* </p>
271+
*/
257272
private final String namingPattern;
258273

259274
/** Stores the priority. */
@@ -281,29 +296,33 @@ private BasicThreadFactory(final Builder builder) {
281296
* Gets the daemon flag. This flag determines whether newly created
282297
* threads should be daemon threads. If <strong>true</strong>, this factory object
283298
* calls {@code setDaemon(true)} on the newly created threads. Result can be
284-
* <strong>null</strong> if no daemon flag was provided at creation time.
299+
* {@code null} if no daemon flag was provided at creation time.
285300
*
286-
* @return the daemon flag
301+
* @return the daemon flag.
287302
*/
288303
public final Boolean getDaemonFlag() {
289304
return daemon;
290305
}
291306

292307
/**
293-
* Gets the naming pattern for naming newly created threads. Result can
294-
* be <strong>null</strong> if no naming pattern was provided.
308+
* Gets the naming pattern for naming newly created threads. Result can be {@code null} if no naming pattern was provided.
309+
* <p>
310+
* The naming pattern is a {@link String#format(String, Object...) format string} that expects a single argument. This argument is the number of the thread
311+
* to be created. For instance, if the naming pattern is {@code "MyThread-%d"}, the first thread created by this factory will be named {@code "MyThread-1"},
312+
* the second one {@code "MyThread-2"} and so on.
313+
* </p>
295314
*
296-
* @return the naming pattern
315+
* @return the naming pattern.
297316
*/
298317
public final String getNamingPattern() {
299318
return namingPattern;
300319
}
301320

302321
/**
303322
* Gets the priority of the threads created by this factory. Result can
304-
* be <strong>null</strong> if no priority was specified.
323+
* be {@code null} if no priority was specified.
305324
*
306-
* @return the priority for newly created threads
325+
* @return the priority for newly created threads.
307326
*/
308327
public final Integer getPriority() {
309328
return priority;
@@ -314,29 +333,29 @@ public final Integer getPriority() {
314333
* class maintains an internal counter that is incremented each time the
315334
* {@link #newThread(Runnable)} method is invoked.
316335
*
317-
* @return the number of threads created by this factory
336+
* @return the number of threads created by this factory.
318337
*/
319338
public long getThreadCount() {
320339
return threadCounter.get();
321340
}
322341

323342
/**
324343
* Gets the {@link UncaughtExceptionHandler} for the threads created by
325-
* this factory. Result can be <strong>null</strong> if no handler was provided.
344+
* this factory. Result can be {@code null} if no handler was provided.
326345
*
327-
* @return the {@link UncaughtExceptionHandler}
346+
* @return the {@link UncaughtExceptionHandler}.
328347
*/
329348
public final Thread.UncaughtExceptionHandler getUncaughtExceptionHandler() {
330349
return uncaughtExceptionHandler;
331350
}
332351

333352
/**
334353
* Gets the wrapped {@link ThreadFactory}. This factory is used for
335-
* actually creating threads. This method never returns <strong>null</strong>. If no
354+
* actually creating threads. This method never returns {@code null}. If no
336355
* {@link ThreadFactory} was passed when this object was created, a default
337356
* thread factory is returned.
338357
*
339-
* @return the wrapped {@link ThreadFactory}
358+
* @return the wrapped {@link ThreadFactory}.
340359
*/
341360
public final ThreadFactory getWrappedFactory() {
342361
return wrappedFactory;
@@ -348,7 +367,7 @@ public final ThreadFactory getWrappedFactory() {
348367
* the wrapped thread factory. It initializes the thread according to the
349368
* options set for this factory.
350369
*
351-
* @param thread the thread to be initialized
370+
* @param thread the thread to be initialized.
352371
*/
353372
private void initializeThread(final Thread thread) {
354373
if (getNamingPattern() != null) {
@@ -371,8 +390,8 @@ private void initializeThread(final Thread thread) {
371390
* factory for creating the thread. Then, on the newly created thread the
372391
* corresponding configuration options are set.
373392
*
374-
* @param runnable the {@link Runnable} to be executed by the new thread
375-
* @return the newly created thread
393+
* @param runnable the {@link Runnable} to be executed by the new thread.
394+
* @return the newly created thread.
376395
*/
377396
@Override
378397
public Thread newThread(final Runnable runnable) {

0 commit comments

Comments
 (0)