标签:线程安全
/** * * @author weip 书中讲到计数器count是线程安全(毋庸置疑,AtomicLong是命令级的线程安全), * 而计数器的状态就是servlet的状态,这是为何? * */ @ThreadSafe public class CountingFactorizer extends GenericServlet implements Servlet { private final AtomicLong count = new AtomicLong(0); public long getCount() { return count.get(); } public void service(ServletRequest req, ServletResponse resp) { BigInteger i = extractFromRequest(req); BigInteger[] factors = factor(i); count.incrementAndGet(); encodeIntoResponse(resp, factors); } void encodeIntoResponse(ServletResponse res, BigInteger[] factors) { } BigInteger extractFromRequest(ServletRequest req) { return null; } BigInteger[] factor(BigInteger i) { return null; } }
标签:线程安全
原文地址:http://weipeng1986.blog.51cto.com/3491277/1854674