Home Atomicity
Post
Cancel

Atomicity

This is an excerpt collected from the book “Java Concurrency in practice”

Java-Concurrency-In-Pracice-book

There is a hit counter which measures the number of requests processed. The obvios approach is to add a long field to the servlet and increment it on each request , as shown in UnsafeCountingFactorizer

 @NotThreadSafe public class UnsafeCountingFactorizer implements Servlet { private long count=0;

public long getCount(){return count;}

public void service(ServletRequest req,ServletResponse resp){
    BigInteger i=extractFromRequest(req);
    BigInteger[] factors=factor(i);
    ++count;
    encodeIntoResponse(resp,factors);
}
} 
This post is licensed under CC BY 4.0 by the author.
Recently Updated
Trending Tags
Trending Tags