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
This commit is contained in:
committed by
Stephane Nicoll
parent
48c2f4d9cc
commit
ecee9c0f9b
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user