mklaca commented on a change in pull request #76: URL: https://github.com/apache/qpid-broker-j/pull/76#discussion_r595127547
########## File path: broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java ########## @@ -542,69 +539,64 @@ public static String getInstalledProtocolsAsString() } @Override - public int incrementConnectionCount() - { - int openConnections = _connectionCount.incrementAndGet(); - _totalConnectionCount.incrementAndGet(); - int maxOpenConnections = getMaxOpenConnections(); - if(maxOpenConnections > 0 - && openConnections > (maxOpenConnections * _connectionWarnCount) / 100 - && _connectionCountWarningGiven.compareAndSet(false, true)) - { - _container.getEventLogger().message(new PortLogSubject(this), - PortMessages.CONNECTION_COUNT_WARN(openConnections, - _connectionWarnCount, - maxOpenConnections)); - } - return openConnections; - } - - @Override - public int decrementConnectionCount() + public long decrementConnectionCount() { - int openConnections = _connectionCount.decrementAndGet(); - int maxOpenConnections = getMaxOpenConnections(); + final long openConnections = _connectionCount.decrementAndGet(); + final long maxOpenConnections = getMaxOpenConnections(); - if(maxOpenConnections > 0 - && openConnections < (maxOpenConnections * square(_connectionWarnCount)) / 10000) + if (maxOpenConnections > 0 + && openConnections < (maxOpenConnections * square(_connectionWarnCount)) / 10000L) { - _connectionCountWarningGiven.compareAndSet(true,false); + _connectionCountWarningGiven.compareAndSet(true, false); } - - return openConnections; } - private static int square(int val) + private static long square(long val) { return val * val; } @Override public boolean canAcceptNewConnection(final SocketAddress remoteSocketAddress) { - String addressString = remoteSocketAddress.toString(); + final String addressString = remoteSocketAddress.toString(); if (_closingOrDeleting.get()) { _container.getEventLogger().message(new PortLogSubject(this), - PortMessages.CONNECTION_REJECTED_CLOSED(addressString)); + PortMessages.CONNECTION_REJECTED_CLOSED(addressString)); return false; } - else if (_maxOpenConnections > 0 && _connectionCount.get() >= _maxOpenConnections) + + final long maxOpenConnections = getMaxOpenConnections(); + if (maxOpenConnections > 0) { - _container.getEventLogger().message(new PortLogSubject(this), - PortMessages.CONNECTION_REJECTED_TOO_MANY(addressString, - _maxOpenConnections)); - return false; + final long currentCount = _connectionCount.getAndUpdate(count -> count < maxOpenConnections ? count + 1L : count) + 1L; Review comment: Every thread has it's own independent stack, hence local variables are not shared among threads. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For additional commands, e-mail: dev-h...@qpid.apache.org