From 023cd42eb2ef5a69d766c605e1a4376633ae8cfd Mon Sep 17 00:00:00 2001 From: Cade Fassett Date: Tue, 20 Sep 2016 14:25:37 -0700 Subject: [PATCH] Update PlatformSpecific to only detect App Engine Standard Environment --- .../metrics/eventstream/HystrixMetricsPoller.java | 2 +- .../concurrency/HystrixConcurrencyStrategy.java | 2 +- .../java/com/netflix/hystrix/util/HystrixTimer.java | 2 +- .../com/netflix/hystrix/util/PlatformSpecific.java | 13 +++++++++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsPoller.java b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsPoller.java index d24a97186..e6510deb5 100644 --- a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsPoller.java +++ b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsPoller.java @@ -80,7 +80,7 @@ public HystrixMetricsPoller(MetricsAsJsonPollerListener listener, int delay) { this.listener = listener; ThreadFactory threadFactory = null; - if (!PlatformSpecific.isAppEngine()) { + if (!PlatformSpecific.isAppEngineStandardEnvironment()) { threadFactory = new MetricsPollerThreadFactory(); } else { threadFactory = PlatformSpecific.getAppEngineThreadFactory(); diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java index a95668896..257559b40 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixConcurrencyStrategy.java @@ -72,7 +72,7 @@ public abstract class HystrixConcurrencyStrategy { */ public ThreadPoolExecutor getThreadPool(final HystrixThreadPoolKey threadPoolKey, HystrixProperty corePoolSize, HystrixProperty maximumPoolSize, HystrixProperty keepAliveTime, TimeUnit unit, BlockingQueue workQueue) { ThreadFactory threadFactory = null; - if (!PlatformSpecific.isAppEngine()) { + if (!PlatformSpecific.isAppEngineStandardEnvironment()) { threadFactory = new ThreadFactory() { protected final AtomicInteger threadNumber = new AtomicInteger(0); diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixTimer.java b/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixTimer.java index 2ee7bf97a..3c10e6276 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixTimer.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/util/HystrixTimer.java @@ -153,7 +153,7 @@ public void initialize() { int coreSize = propertiesStrategy.getTimerThreadPoolProperties().getCorePoolSize().get(); ThreadFactory threadFactory = null; - if (!PlatformSpecific.isAppEngine()) { + if (!PlatformSpecific.isAppEngineStandardEnvironment()) { threadFactory = new ThreadFactory() { final AtomicInteger counter = new AtomicInteger(); diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/util/PlatformSpecific.java b/hystrix-core/src/main/java/com/netflix/hystrix/util/PlatformSpecific.java index 263b63667..4cac86f15 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/util/PlatformSpecific.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/util/PlatformSpecific.java @@ -19,26 +19,31 @@ import java.util.concurrent.ThreadFactory; public class PlatformSpecific { - private final boolean isAppEngine; + private final boolean isAppEngineStandardEnvironment; private static PlatformSpecific INSTANCE = new PlatformSpecific(); private PlatformSpecific() { - isAppEngine = determineAppEngineReflectively(); + isAppEngineStandardEnvironment = determineAppEngineReflectively(); } - public static boolean isAppEngine() { - return INSTANCE.isAppEngine; + public static boolean isAppEngineStandardEnvironment() { + return INSTANCE.isAppEngineStandardEnvironment; } /* * This detection mechanism is from Guava - specifically * http://docs.guava-libraries.googlecode.com/git/javadoc/src-html/com/google/common/util/concurrent/MoreExecutors.html#line.766 + * Added GAE_LONG_APP_ID check to detect only AppEngine Standard Environment */ private static boolean determineAppEngineReflectively() { if (System.getProperty("com.google.appengine.runtime.environment") == null) { return false; } + // GAE_LONG_APP_ID is only set in the GAE Flexible Environment, where we want standard threading + if (System.getenv("GAE_LONG_APP_ID") != null) { + return false; + } try { // If the current environment is null, we're not inside AppEngine. return Class.forName("com.google.apphosting.api.ApiProxy")