日期:2014-05-18  浏览次数:20755 次

一个计数器的代码问题,我新手,希望得到详细解答。
<%
Integer   count   =   null;//同步处理
synchronized   (application)
{
count=(Integer)application.getAttribute( "basic.counter ");
if(count==null)
count   =   new   Integer   (0);
count   =   new   Integer   (count.intValue()+1);
application.setAttribute( "basic.counter ",count);
}
%>
上述代码中的count   =   new   Integer   (0);
count   =   new   Integer   (count.intValue()+1);是什么意思
还有别的希望也能得到些讲解,帮帮我们这些小菜鸟吧,在线等ING。!!!


------解决方案--------------------
<%
Integer count = null;//声明一个空的Integer对象
synchronized (application) //以application对象作为碩旗标
{
count=(Integer)application.getAttribute( "basic.counter "); //从application对象中读取属性值
if(count==null) //如果count 是空
count = new Integer (0); //创建一个指向0的Integer对象
count = new Integer (count.intValue()+1); //创建一个指向count.intValue()+1的Integer对象
application.setAttribute( "basic.counter ",count); //保存该对象到application中
}
%>

这段代码每次增加一个浏览量就创建一个新的Integer对象,这样应该是不好的。

个人愚见