`

servlet 线程安全 application.setattribute,加上synchronized

    博客分类:
  • java
 
阅读更多
http://www.alixixi.com/Dev/Web/JSP/jsp7/2007/2007020914328.html

servletContext application=getServletContext();

后面的一段函数是env.java的片断,可以看看在servlet中如何使用application变量的。

Integer count = null;

synchronized (application) {

  count = (Integer) application.getAttribute("change");

  if (count == null)

    count = new Integer(0);

  count = new Integer(count.intValue() + 1);

  application.setAttribute("change", count);

}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics