读书人

servlet 线程安全 application.setatt

发布时间: 2013-03-25 15:43:04 作者: rapoo

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

}


读书人网 >编程

热点推荐