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

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);

}


你可能感兴趣的:(synchronized)