コメント
サイト運営のための寄付
作成者: 白鷹2
ページ番号: 1228093883_1228271704
作成日: 2008-12-03
修正日: 2008-12-03
カウント
サーブレットでのカウント 書籍より引用
@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);
}
}
以下は、count変数の値を増やす部分が、安全ではない
@NotThreadSafe
public class UnsafeCountingFactorizer extends GenericServlet 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);
}
}
©2008-2009 PostTips All Rights Reserved.
新規ページの作成
タイトル:
要約
新規画像の登録
タイトル:
画像ファイルの指定
タイトルの修正
画像タイトルの修正
要約の修正
コメントの書き込み
コメント: