Skip to content

Commit 7d30386

Browse files
spot bugs repair (#4788)
1 parent 11d8645 commit 7d30386

File tree

16 files changed

+37
-35
lines changed

16 files changed

+37
-35
lines changed

clients/http-client-common/src/main/java/org/apache/servicecomb/http/client/common/AbstractAddressManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class AbstractAddressManager {
6666

6767
private final List<String> isolationRegionAddress = new ArrayList<>();
6868

69-
private boolean addressAutoRefreshed = false;
69+
private volatile boolean addressAutoRefreshed = false;
7070

7171
private final Object lock = new Object();
7272

clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterWatch.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.ExecutorService;
2323
import java.util.concurrent.Executors;
2424
import java.util.concurrent.atomic.AtomicBoolean;
25+
import java.util.concurrent.atomic.AtomicInteger;
2526

2627
import org.apache.servicecomb.http.client.auth.RequestAuthHeaderProvider;
2728
import org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties;
@@ -67,7 +68,7 @@ public class ServiceCenterWatch implements WebSocketListener {
6768

6869
private String serviceId;
6970

70-
private int continuousError = 0;
71+
private AtomicInteger continuousError = new AtomicInteger(0);
7172

7273
private final AtomicBoolean reconnecting = new AtomicBoolean(false);
7374

@@ -143,19 +144,19 @@ private void reconnect() {
143144
if (reconnecting.getAndSet(true)) {
144145
return;
145146
}
146-
continuousError++;
147+
continuousError.incrementAndGet();
147148
if (webSocketTransport != null) {
148149
webSocketTransport.close();
149150
}
150151
startWatch();
151152
}
152153

153154
private void backOff() {
154-
if (this.continuousError <= 0) {
155+
if (this.continuousError.get() <= 0) {
155156
return;
156157
}
157158
try {
158-
Thread.sleep(Math.min(SLEEP_MAX, this.continuousError * this.continuousError * SLEEP_BASE));
159+
Thread.sleep(Math.min(SLEEP_MAX, this.continuousError.get() * this.continuousError.get() * SLEEP_BASE));
159160
} catch (InterruptedException e) {
160161
// do not care
161162
}
@@ -183,7 +184,7 @@ public void onOpen(ServerHandshake serverHandshake) {
183184
LOGGER.info("web socket connected to server {}, status={}, message={}", currentServerUri,
184185
serverHandshake.getHttpStatus(),
185186
serverHandshake.getHttpStatusMessage());
186-
continuousError = 0;
187+
continuousError.set(0);
187188
reconnecting.set(false);
188189
}
189190
}

core/src/main/java/org/apache/servicecomb/core/Invocation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ static Collection<TraceIdGenerator> loadTraceIdGenerators() {
8484
// 同步模式:避免应答在网络线程中处理解码等等业务级逻辑
8585
private Executor responseExecutor;
8686

87-
private boolean sync = true;
87+
private volatile boolean sync = true;
8888

8989
private final InvocationStageTrace invocationStageTrace = new InvocationStageTrace(this);
9090

9191
private HttpServletRequestEx requestEx;
9292

93-
private boolean finished;
93+
private volatile boolean finished;
9494

95-
private long invocationId;
95+
private volatile long invocationId;
9696

9797
private TraceIdLogger traceIdLogger;
9898

core/src/main/java/org/apache/servicecomb/core/executor/GroupExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public GroupExecutor init(String groupName) {
100100
return this;
101101
}
102102

103-
public void initConfig() {
103+
public synchronized void initConfig() {
104104
if (LOG_PRINTED.compareAndSet(false, true)) {
105105
LOGGER.info("thread pool rules:\n"
106106
+ "1.use core threads.\n"

demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,15 @@ public Generic<Generic<User>> testGenericGenericUser(@RequestBody Generic<Generi
495495
return input;
496496
}
497497

498-
private boolean testvoidInRPCSuccess = false;
498+
private volatile boolean testvoidInRPCSuccess = false;
499499

500500
@GetMapping(path = "/testvoidInRPC")
501501
public void testvoidInRPC() {
502502
LOGGER.info("testvoidInRPC() is called!");
503503
testvoidInRPCSuccess = true;
504504
}
505505

506-
private boolean testVoidInRPCSuccess = false;
506+
private volatile boolean testVoidInRPCSuccess = false;
507507

508508
@GetMapping(path = "/testVoidInRPC")
509509
public Void testVoidInRPC() {
@@ -512,15 +512,15 @@ public Void testVoidInRPC() {
512512
return null;
513513
}
514514

515-
private boolean testvoidInRestTemplateSuccess = false;
515+
private volatile boolean testvoidInRestTemplateSuccess = false;
516516

517517
@GetMapping(path = "/testvoidInRestTemplate")
518518
public void testvoidInRestTemplate() {
519519
LOGGER.info("testvoidInRestTemplate() is called!");
520520
testvoidInRestTemplateSuccess = true;
521521
}
522522

523-
private boolean testVoidInRestTemplateSuccess = false;
523+
private volatile boolean testVoidInRestTemplateSuccess = false;
524524

525525
@GetMapping(path = "/testVoidInRestTemplate")
526526
public Void testVoidInRestTemplate() {

foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/cache/VersionedCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface IsEmpty {
3030
boolean isEmpty();
3131
}
3232

33-
protected int cacheVersion;
33+
protected volatile int cacheVersion;
3434

3535
// an optional name
3636
protected String name;

foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/IpPort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import com.google.common.base.Objects;
2323

2424
public class IpPort {
25-
private String hostOrIp;
25+
private volatile String hostOrIp;
2626

27-
private int port;
27+
private volatile int port;
2828

2929
private volatile InetSocketAddress socketAddress;
3030

foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/discovery/DiscoveryTreeNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public class DiscoveryTreeNode extends VersionedCache {
2626
private volatile boolean childrenInited;
2727

28-
private int level;
28+
private volatile int level;
2929

3030
protected Map<String, Object> attributes = new ConcurrentHashMapEx<>();
3131

foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/client/tcp/AbstractTcpClientPackage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public static long getAndIncRequestId() {
2727
return reqId.getAndIncrement();
2828
}
2929

30-
private long msRequestTimeout;
30+
private volatile long msRequestTimeout;
3131

32-
private long finishWriteToBuffer;
32+
private volatile long finishWriteToBuffer;
3333

3434
protected long msgId = getAndIncRequestId();
3535

foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/client/tcp/TcpClientConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ enum Status {
6161

6262
private final InetSocketAddress socketAddress;
6363

64-
private boolean localSupportLogin = false;
64+
private volatile boolean localSupportLogin = false;
6565

6666
private final boolean remoteSupportLogin;
6767

0 commit comments

Comments
 (0)