Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 936cc29

Browse files
author
Adam Lindenthal
committed
Resolved TODO in AbstractThreadPoolProvider (+ minor adjustments)
Change-Id: I3ffca32bb4ebc145e71b702193fb968618bd3227
1 parent 7b539df commit 936cc29

File tree

1 file changed

+38
-52
lines changed

1 file changed

+38
-52
lines changed

core-common/src/main/java/org/glassfish/jersey/spi/AbstractThreadPoolProvider.java

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2015-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -81,8 +81,7 @@
8181
* @author Marek Potociar (marek.potociar at oracle.com)
8282
* @since 2.18
8383
*/
84-
// TODO implement AutoCloseable once switched to Java SE 7+
85-
public abstract class AbstractThreadPoolProvider<E extends ThreadPoolExecutor> {
84+
public abstract class AbstractThreadPoolProvider<E extends ThreadPoolExecutor> implements AutoCloseable {
8685

8786
private static final ExtendedLogger LOGGER = new ExtendedLogger(
8887
Logger.getLogger(AbstractThreadPoolProvider.class.getName()), Level.FINEST);
@@ -95,13 +94,7 @@ public abstract class AbstractThreadPoolProvider<E extends ThreadPoolExecutor> {
9594
private final String name;
9695
private final AtomicBoolean closed = new AtomicBoolean(false);
9796
private final LazyValue<E> lazyExecutorServiceProvider =
98-
Values.lazy(new Value<E>() {
99-
100-
@Override
101-
public E get() {
102-
return createExecutor(getCorePoolSize(), createThreadFactory(), getRejectedExecutionHandler());
103-
}
104-
});
97+
Values.lazy((Value<E>) () -> createExecutor(getCorePoolSize(), createThreadFactory(), getRejectedExecutionHandler()));
10598

10699
/**
107100
* Inheritance constructor.
@@ -211,11 +204,8 @@ protected int getCorePoolSize() {
211204
* @see #createExecutor
212205
*/
213206
protected RejectedExecutionHandler getRejectedExecutionHandler() {
214-
return new RejectedExecutionHandler() {
215-
@Override
216-
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) {
217-
// TODO: implement the rejected execution handler method.
218-
}
207+
return (r, executor) -> {
208+
// TODO: implement the rejected execution handler method.
219209
};
220210
}
221211

@@ -345,51 +335,47 @@ private static PrivilegedAction<?> shutdownExecutor(
345335
final int terminationTimeout,
346336
final TimeUnit terminationTimeUnit) {
347337

348-
return new PrivilegedAction<Void>() {
349-
350-
@Override
351-
public Void run() {
352-
if (!executorService.isShutdown()) {
353-
executorService.shutdown();
354-
}
355-
if (executorService.isTerminated()) {
356-
return null;
357-
}
338+
return (PrivilegedAction<Void>) () -> {
339+
if (!executorService.isShutdown()) {
340+
executorService.shutdown();
341+
}
342+
if (executorService.isTerminated()) {
343+
return null;
344+
}
358345

359-
boolean terminated = false;
360-
boolean interrupted = false;
361-
try {
362-
terminated = executorService.awaitTermination(terminationTimeout, terminationTimeUnit);
363-
} catch (InterruptedException e) {
364-
if (LOGGER.isDebugLoggable()) {
365-
LOGGER.log(LOGGER.getDebugLevel(),
366-
"Interrupted while waiting for thread pool executor " + executorName + " to shutdown.", e);
367-
}
368-
interrupted = true;
346+
boolean terminated = false;
347+
boolean interrupted = false;
348+
try {
349+
terminated = executorService.awaitTermination(terminationTimeout, terminationTimeUnit);
350+
} catch (InterruptedException e) {
351+
if (LOGGER.isDebugLoggable()) {
352+
LOGGER.log(LOGGER.getDebugLevel(),
353+
"Interrupted while waiting for thread pool executor " + executorName + " to shutdown.", e);
369354
}
355+
interrupted = true;
356+
}
370357

371-
try {
372-
if (!terminated) {
373-
final List<Runnable> cancelledTasks = executorService.shutdownNow();
374-
for (Runnable cancelledTask : cancelledTasks) {
375-
if (cancelledTask instanceof Future) {
376-
((Future) cancelledTask).cancel(true);
377-
}
378-
}
379-
380-
if (LOGGER.isDebugLoggable()) {
381-
LOGGER.debugLog("Thread pool executor {0} forced-shut down. List of cancelled tasks: {1}",
382-
executorName, cancelledTasks);
358+
try {
359+
if (!terminated) {
360+
final List<Runnable> cancelledTasks = executorService.shutdownNow();
361+
for (Runnable cancelledTask : cancelledTasks) {
362+
if (cancelledTask instanceof Future) {
363+
((Future) cancelledTask).cancel(true);
383364
}
384365
}
385-
} finally {
386-
if (interrupted) {
387-
// restoring the interrupt flag
388-
Thread.currentThread().interrupt();
366+
367+
if (LOGGER.isDebugLoggable()) {
368+
LOGGER.debugLog("Thread pool executor {0} forced-shut down. List of cancelled tasks: {1}",
369+
executorName, cancelledTasks);
389370
}
390371
}
391-
return null;
372+
} finally {
373+
if (interrupted) {
374+
// restoring the interrupt flag
375+
Thread.currentThread().interrupt();
376+
}
392377
}
378+
return null;
393379
};
394380
}
395381
}

0 commit comments

Comments
 (0)