diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/CodahaleMetricWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/CodahaleMetricWriter.java index 715fda39280..5f3b1cc0a59 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/CodahaleMetricWriter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/CodahaleMetricWriter.java @@ -90,25 +90,25 @@ public class CodahaleMetricWriter implements MetricWriter { } else { final double gauge = value.getValue().doubleValue(); - Object lock = null; - if (this.gaugeLocks.containsKey(name)) { - lock = this.gaugeLocks.get(name); - } - else { - this.gaugeLocks.putIfAbsent(name, new Object()); - lock = this.gaugeLocks.get(name); - } - // Ensure we synchronize to avoid another thread pre-empting this thread after // remove causing an error in CodaHale metrics // NOTE: CodaHale provides no way to do this atomically - synchronized (lock) { + synchronized (getGuageLock(name)) { this.registry.remove(name); this.registry.register(name, new SimpleGauge(gauge)); } } } + private Object getGuageLock(String name) { + Object lock = this.gaugeLocks.get(name); + if (lock == null) { + this.gaugeLocks.putIfAbsent(name, new Object()); + lock = this.gaugeLocks.get(name); + } + return lock; + } + @Override public void reset(String metricName) { this.registry.remove(metricName); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java index cb29b3a3337..55d6b66a750 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java @@ -56,8 +56,8 @@ import org.springframework.web.filter.OncePerRequestFilter; */ @Component @Order(Ordered.HIGHEST_PRECEDENCE) -class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer implements - Filter, NonEmbeddedServletContainerFactory { +public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer + implements Filter, NonEmbeddedServletContainerFactory { private static Log logger = LogFactory.getLog(ErrorPageFilter.class);