From 43943c7ab11b5b4c4b2eb905aeea190544b83f3a Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 19 Nov 2013 17:57:25 +0100 Subject: [PATCH] [#1994] DefaultPromise.cancel() should reuse CancellationException for performance reasons --- .../io/netty/util/concurrent/DefaultPromise.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java b/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java index d054ae731b..3a3940b793 100644 --- a/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java +++ b/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java @@ -16,6 +16,7 @@ package io.netty.util.concurrent; import io.netty.util.Signal; +import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; @@ -39,8 +40,14 @@ public class DefaultPromise extends AbstractFuture implements Promise { return 0; } }; - private static final Signal SUCCESS = Signal.valueOf(DefaultPromise.class, "SUCCESS"); - private static final Signal UNCANCELLABLE = Signal.valueOf(DefaultPromise.class, "UNCANCELLABLE"); + private static final Signal SUCCESS = Signal.valueOf(DefaultPromise.class.getName() + ".SUCCESS"); + private static final Signal UNCANCELLABLE = Signal.valueOf(DefaultPromise.class.getName() + ".UNCANCELLABLE"); + private static final CauseHolder CANCELLATION_CAUSE_HOLDER = new CauseHolder(new CancellationException()); + + static { + CANCELLATION_CAUSE_HOLDER.cause.setStackTrace(EmptyArrays.EMPTY_STACK_TRACE); + } + private final EventExecutor executor; private volatile Object result; @@ -424,7 +431,7 @@ public class DefaultPromise extends AbstractFuture implements Promise { return false; } - this.result = new CauseHolder(new CancellationException()); + this.result = CANCELLATION_CAUSE_HOLDER; if (hasWaiters()) { notifyAll(); }