Skip to content
Snippets Groups Projects
Commit 96627113 authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Replace synchronized methods with AtomicInteger fields.

parent 355dbc15
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,7 @@ import java.util.Comparator; ...@@ -51,6 +51,7 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Stack; import java.util.Stack;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
public class CellHandler extends ContextHandler { public class CellHandler extends ContextHandler {
private static final org.eclipse.jetty.util.log.Logger LOG = Log.getLogger(CellHandler.class); private static final org.eclipse.jetty.util.log.Logger LOG = Log.getLogger(CellHandler.class);
...@@ -163,19 +164,9 @@ public class CellHandler extends ContextHandler { ...@@ -163,19 +164,9 @@ public class CellHandler extends ContextHandler {
private Stack<MemoryOutputStream> cachedBuffers = null; private Stack<MemoryOutputStream> cachedBuffers = null;
private final int INITIAL_BUFFER_SIZE = 2048; private final int INITIAL_BUFFER_SIZE = 2048;
private long accumulation = 0;
private long uncompressedAccumulation = 0;
private final AtomicInteger compressedAccumulation = new AtomicInteger(0);
private synchronized long addToAccumulation(final int value) { private final AtomicInteger uncompressedAccumulation = new AtomicInteger(0);
accumulation += value;
return accumulation;
}
private synchronized long addToUncompressedAccumulation(final int value) {
uncompressedAccumulation += value;
return uncompressedAccumulation;
}
public CellHandler(final String baseUrl, public CellHandler(final String baseUrl,
...@@ -386,8 +377,8 @@ public class CellHandler extends ContextHandler { ...@@ -386,8 +377,8 @@ public class CellHandler extends ContextHandler {
returnBufferForReuse(cellCompressionStream); returnBufferForReuse(cellCompressionStream);
stopwatch.stop(); stopwatch.stop();
final long currentlySent = addToAccumulation(compressedContentLength); final long currentlySent = compressedAccumulation.addAndGet(compressedContentLength);
final long uncompressedWouldSent = addToUncompressedAccumulation(data.length * 2); final long uncompressedWouldSent = uncompressedAccumulation.addAndGet(data.length * 2);
if (compressionParams.isVerbose()) { if (compressionParams.isVerbose()) {
...@@ -409,8 +400,8 @@ public class CellHandler extends ContextHandler { ...@@ -409,8 +400,8 @@ public class CellHandler extends ContextHandler {
} }
private void respondWithCompressionSummary(final Request baseRequest, final HttpServletResponse response) throws IOException { private void respondWithCompressionSummary(final Request baseRequest, final HttpServletResponse response) throws IOException {
final long currentlySent = addToAccumulation(0); final long currentlySent = compressedAccumulation.get();
final long uncompressedWouldSent = addToUncompressedAccumulation(0); final long uncompressedWouldSent = uncompressedAccumulation.get();
final double sentKB = ((double) currentlySent / 1000.0); final double sentKB = ((double) currentlySent / 1000.0);
final double sentMB = ((double) currentlySent / 1000.0) / 1000.0; final double sentMB = ((double) currentlySent / 1000.0) / 1000.0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment