extract duplicate code into method (#8720)
Motivation: Clean up code to increase readability. Modification: Extract duplicate code blocks into method. Result: Less code duplication
This commit is contained in:
parent
ddc9f8bf1d
commit
ae1340fd72
@ -576,19 +576,8 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx
|
|||||||
gracefulShutdownQuietPeriod = unit.toNanos(quietPeriod);
|
gracefulShutdownQuietPeriod = unit.toNanos(quietPeriod);
|
||||||
gracefulShutdownTimeout = unit.toNanos(timeout);
|
gracefulShutdownTimeout = unit.toNanos(timeout);
|
||||||
|
|
||||||
if (oldState == ST_NOT_STARTED) {
|
if (ensureThreadStarted(oldState)) {
|
||||||
try {
|
return terminationFuture;
|
||||||
doStartThread();
|
|
||||||
} catch (Throwable cause) {
|
|
||||||
STATE_UPDATER.set(this, ST_TERMINATED);
|
|
||||||
terminationFuture.tryFailure(cause);
|
|
||||||
|
|
||||||
if (!(cause instanceof Exception)) {
|
|
||||||
// Also rethrow as it may be an OOME for example
|
|
||||||
PlatformDependent.throwException(cause);
|
|
||||||
}
|
|
||||||
return terminationFuture;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wakeup) {
|
if (wakeup) {
|
||||||
@ -639,19 +628,8 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldState == ST_NOT_STARTED) {
|
if (ensureThreadStarted(oldState)) {
|
||||||
try {
|
return;
|
||||||
doStartThread();
|
|
||||||
} catch (Throwable cause) {
|
|
||||||
STATE_UPDATER.set(this, ST_TERMINATED);
|
|
||||||
terminationFuture.tryFailure(cause);
|
|
||||||
|
|
||||||
if (!(cause instanceof Exception)) {
|
|
||||||
// Also rethrow as it may be an OOME for example
|
|
||||||
PlatformDependent.throwException(cause);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wakeup) {
|
if (wakeup) {
|
||||||
@ -865,6 +843,24 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean ensureThreadStarted(int oldState) {
|
||||||
|
if (oldState == ST_NOT_STARTED) {
|
||||||
|
try {
|
||||||
|
doStartThread();
|
||||||
|
} catch (Throwable cause) {
|
||||||
|
STATE_UPDATER.set(this, ST_TERMINATED);
|
||||||
|
terminationFuture.tryFailure(cause);
|
||||||
|
|
||||||
|
if (!(cause instanceof Exception)) {
|
||||||
|
// Also rethrow as it may be an OOME for example
|
||||||
|
PlatformDependent.throwException(cause);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void doStartThread() {
|
private void doStartThread() {
|
||||||
assert thread == null;
|
assert thread == null;
|
||||||
executor.execute(new Runnable() {
|
executor.execute(new Runnable() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user