Commit ecee9c0f authored by dreis2211's avatar dreis2211 Committed by Stephane Nicoll

Avoid unnecessary explicit initialization of Atomics

Constructor calls like new AtomicInteger(0) cause a volatile write that
can be saved in cases where the constructor parameter is the default
value.

See gh-23575
parent 48c2f4d9
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -38,7 +38,7 @@ public final class OnlyOnceLoggingDenyMeterFilter implements MeterFilter {
private static final Log logger = LogFactory.getLog(OnlyOnceLoggingDenyMeterFilter.class);
private final AtomicBoolean alreadyWarned = new AtomicBoolean(false);
private final AtomicBoolean alreadyWarned = new AtomicBoolean();
private final Supplier<String> message;
......
......@@ -87,7 +87,7 @@ class Neo4jHealthIndicatorTests {
ResultSummary resultSummary = ResultSummaryMock.createResultSummary("4711", "My Home", "");
Session session = mock(Session.class);
Result statementResult = mockStatementResult(resultSummary, "some edition");
AtomicInteger count = new AtomicInteger(0);
AtomicInteger count = new AtomicInteger();
given(session.run(anyString())).will((invocation) -> {
if (count.compareAndSet(0, 1)) {
throw new SessionExpiredException("Session expired");
......
......@@ -66,7 +66,7 @@ class Neo4jReactiveHealthIndicatorTest {
ResultSummary resultSummary = ResultSummaryMock.createResultSummary("4711", "My Home", "");
RxSession session = mock(RxSession.class);
RxResult statementResult = mockStatementResult(resultSummary, "some edition");
AtomicInteger count = new AtomicInteger(0);
AtomicInteger count = new AtomicInteger();
given(session.run(anyString())).will((invocation) -> {
if (count.compareAndSet(0, 1)) {
throw new SessionExpiredException("Session expired");
......
......@@ -60,7 +60,7 @@ public class BackgroundPreinitializer implements ApplicationListener<SpringAppli
*/
public static final String IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME = "spring.backgroundpreinitializer.ignore";
private static final AtomicBoolean preinitializationStarted = new AtomicBoolean(false);
private static final AtomicBoolean preinitializationStarted = new AtomicBoolean();
private static final CountDownLatch preinitializationComplete = new CountDownLatch(1);
......
......@@ -79,7 +79,7 @@ public class SpringApplicationBuilder {
private SpringApplicationBuilder parent;
private final AtomicBoolean running = new AtomicBoolean(false);
private final AtomicBoolean running = new AtomicBoolean();
private final Set<Class<?>> sources = new LinkedHashSet<>();
......
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -86,7 +86,7 @@ public class ApplicationPidFileWriter implements ApplicationListener<SpringAppli
FAIL_ON_WRITE_ERROR_PROPERTIES = Collections.unmodifiableList(properties);
}
private static final AtomicBoolean created = new AtomicBoolean(false);
private static final AtomicBoolean created = new AtomicBoolean();
private int order = Ordered.HIGHEST_PRECEDENCE + 13;
......
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -74,7 +74,7 @@ public class ContextIdApplicationContextInitializer
*/
static class ContextId {
private final AtomicLong children = new AtomicLong(0);
private final AtomicLong children = new AtomicLong();
private final String id;
......
......@@ -170,7 +170,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
private static final Class<?>[] SOURCE_TYPES = { SpringApplication.class, ApplicationContext.class };
private static final AtomicBoolean shutdownHookRegistered = new AtomicBoolean(false);
private static final AtomicBoolean shutdownHookRegistered = new AtomicBoolean();
private final Log logger = LogFactory.getLog(getClass());
......
......@@ -1506,7 +1506,7 @@ class SpringApplicationTests {
@Bean
AtomicInteger counter() {
return new AtomicInteger(0);
return new AtomicInteger();
}
@Bean
......@@ -1529,7 +1529,7 @@ class SpringApplicationTests {
@Bean
AtomicInteger counter() {
return new AtomicInteger(0);
return new AtomicInteger();
}
@Bean
......@@ -1553,7 +1553,7 @@ class SpringApplicationTests {
@Bean
AtomicInteger counter() {
return new AtomicInteger(0);
return new AtomicInteger();
}
@Bean
......
......@@ -1355,7 +1355,7 @@ public abstract class AbstractServletWebServerFactoryTests {
private class TestGzipInputStreamFactory implements InputStreamFactory {
private final AtomicBoolean requested = new AtomicBoolean(false);
private final AtomicBoolean requested = new AtomicBoolean();
@Override
public InputStream create(InputStream in) throws IOException {
......
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -28,7 +28,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
public class SnakeWebSocketHandler extends TextWebSocketHandler {
private static final AtomicInteger snakeIds = new AtomicInteger(0);
private static final AtomicInteger snakeIds = new AtomicInteger();
private static final Random random = new Random();
......
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -28,7 +28,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
public class SnakeWebSocketHandler extends TextWebSocketHandler {
private static final AtomicInteger snakeIds = new AtomicInteger(0);
private static final AtomicInteger snakeIds = new AtomicInteger();
private static final Random random = new Random();
......
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -28,7 +28,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
public class SnakeWebSocketHandler extends TextWebSocketHandler {
private static final AtomicInteger snakeIds = new AtomicInteger(0);
private static final AtomicInteger snakeIds = new AtomicInteger();
private static final Random random = new Random();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment