diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java b/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java index 620949ab9..c43616d63 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java @@ -3,9 +3,12 @@ import static org.junit.Assert.*; import java.util.LinkedList; +import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.netflix.hystrix.HystrixCommand.Setter; import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy; @@ -15,6 +18,8 @@ */ public class Hystrix { + private static final Logger logger = LoggerFactory.getLogger(Hystrix.class); + /** * Reset state and release resources in use (such as thread-pools). *

@@ -81,11 +86,24 @@ public static HystrixCommandKey getCurrentThreadExecutingCommand() { } /* package */static void startCurrentThreadExecutingCommand(HystrixCommandKey key) { - currentCommand.get().push(key); + try { + currentCommand.get().push(key); + } catch (Exception e) { + logger.warn("Unable to record command starting", e); + } } /* package */static void endCurrentThreadExecutingCommand() { - currentCommand.get().pop(); + try { + if (!currentCommand.get().isEmpty()) { + currentCommand.get().pop(); + } + } catch (NoSuchElementException e) { + // this shouldn't be possible since we check for empty above and this is thread-isolated + logger.debug("No command found to end.", e); + } catch (Exception e) { + logger.warn("Unable to end command.", e); + } } public static class UnitTest {