2 weipeng19861130 weipeng19861130 于 2016.09.20 21:38 提问

java并发编程学习书中遇到不解1

/**

  • @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;
    }
    }

1个回答

devmiao
devmiao   Ds   Rxr 2016.09.21 00:40
Csdn user default icon
上传中...
上传图片
插入图片