首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2013-03-25 
servlet 线程安全 application.setattribute,加上synchronizedhttp://www.alixixi.com/Dev/Web/JSP/jsp7/2

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

}


热点排行