Skip to content

Commit

Permalink
More thread-safety
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1703849 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Sep 18, 2015
1 parent 2db254d commit 1484f3e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions java/org/apache/catalina/tribes/membership/MemberImpl.java
Expand Up @@ -21,6 +21,7 @@
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;


import org.apache.catalina.tribes.Member; import org.apache.catalina.tribes.Member;
import org.apache.catalina.tribes.io.XByteBuffer; import org.apache.catalina.tribes.io.XByteBuffer;
Expand Down Expand Up @@ -66,7 +67,8 @@ public class MemberImpl implements Member, java.io.Externalizable {
/** /**
* Counter for how many broadcast messages have been sent from this member * Counter for how many broadcast messages have been sent from this member
*/ */
protected int msgCount = 0; protected AtomicInteger msgCount = new AtomicInteger(0);

/** /**
* The number of milliseconds since this member was * The number of milliseconds since this member was
* created, is kept track of using the start time * created, is kept track of using the start time
Expand Down Expand Up @@ -156,7 +158,7 @@ public boolean isFailing() {
* Increment the message count. * Increment the message count.
*/ */
protected void inc() { protected void inc() {
msgCount++; msgCount.incrementAndGet();
} }


/** /**
Expand Down Expand Up @@ -458,7 +460,7 @@ public String getHostname() {
} }


public int getMsgCount() { public int getMsgCount() {
return this.msgCount; return msgCount.get();
} }


/** /**
Expand Down Expand Up @@ -587,7 +589,7 @@ public void setHostname(String host) throws IOException {
} }


public void setMsgCount(int msgCount) { public void setMsgCount(int msgCount) {
this.msgCount = msgCount; this.msgCount.set(msgCount);
} }


public synchronized void setPort(int port) { public synchronized void setPort(int port) {
Expand Down

0 comments on commit 1484f3e

Please sign in to comment.