I am trying to use a counter for detecting number of unique words in a text send over HTTP methods. As I need to ensure concurrency on the value of this counter, I have changed it to AtomicInteger
.
In certain cases I would like to get the current value of the counter and reset it to zero. If I understand it correctly, I must not use get()
and set(0)
methods separately like this, but use the getAndUpdate() method, BUT! I do not know how to implement the IntUnaryOperator for this reset and if it is even possible to do that on Java 6 server.
Thank you.
public class Server {
static AtomicInteger counter = new AtomicInteger(0);
static class implements HttpHandler {
@Override
public void handle(HttpExchange spojeni) throws IOException {
counter.getAndUpdate(???);
}
}
}