以下为101-200行代码
System.out.print(ee+""+new java.util.Date());
}
ResultSet rs=null;
application.setAttribute(counterSite+"Date1",new java.util.Date());//站点定时时间
sql="select id,R_TODAY_SUM,R_TOM_SUM,R_THIS_MONTH_SUM,R_TOTAL_SUM,R_TOTAL_DAY,R_COUNT_DATE from inber_count_account where ACCOUNT_SIT_ADD like '%"+counterSite+"%'";
//out.print(sql);
rs=stmt.executeQuery(sql);
if(rs.next())
{
application.setAttribute(counterSite+"_checkAccount",new String("ok"));
application.setAttribute(counterSite+"_id",new Integer(rs.getInt(1)));
application.setAttribute(counterSite+"_R_TODAY_SUM",new Integer(rs.getInt(2)));
application.setAttribute(counterSite+"_R_TOM_SUM",new Integer(rs.getInt(3)));
application.setAttribute(counterSite+"_R_THIS_MONTH_SUM",new Integer(rs.getInt(4)));
application.setAttribute(counterSite+"_R_TOTAL_SUM",new Integer(rs.getInt(5)));
application.setAttribute(counterSite+"_R_TOTAL_DAY",new Integer(rs.getInt(6))); //****
application.setAttribute(counterSite+"_R_COUNT_DATE",new String(rs.getString("R_COUNT_DATE"))); }
rs.close();
stmt.close();
}
else
{
if((application.getAttribute(counterSite+"_checkAccount").toString()).equals("ok"))//校验此计数器账号引用是否存在
{
Date accessTime=null;
//刷新率 start---------------------------------- application.setAttribute(counterSite+"_R_TODAY_SUM",new Integer(Integer.parseInt((application.getAttribute(counterSite+"_R_TODAY_SUM").toString()))+1));
application.setAttribute(counterSite+"_R_THIS_MONTH_SUM",new Integer(Integer.parseInt((application.getAttribute(counterSite+"_R_THIS_MONTH_SUM").toString()))+1));
application.setAttribute(counterSite+"_R_TOTAL_SUM",new Integer(Integer.parseInt((application.getAttribute(counterSite+"_R_TOTAL_SUM").toString()))+1));
String d2=application.getAttribute(counterSite+"_R_COUNT_DATE").toString();
//当日期改变时,清除当天的计数
String tYear,tMonth,tDay;
tYear=d2.substring(0,4);
tMonth=d2.substring(5,7);
tDay=d2.substring(8,10); if(!(d1.equals(d2)))
{
int todaysum=Integer.parseInt((application.getAttribute(counterSite+"_R_TODAY_SUM").toString()));
int totalday=Integer.parseInt((application.getAttribute(counterSite+"_R_TOTAL_DAY").toString()));
application.setAttribute(counterSite+"_R_TOM_SUM",new Integer(todaysum));
application.setAttribute(counterSite+"_R_TODAY_SUM",new Integer(0));
application.setAttribute(counterSite+"_R_TOTAL_DAY",new Integer(totalday+1));
application.setAttribute(counterSite+"_R_COUNT_DATE",new String(d1));
try{
CallableStatement cstmt4=null;
pString = "{call p_setDetailList3('"+tYear+"', '"+tMonth+"', '"+tDay+"',"+todaysum+", '"+d2+"',"+Integer.parseInt((application.getAttribute(counterSite+"_id").toString()))+")}";
cstmt4=con.prepareCall(pString);
cstmt4.executeUpdate();
cstmt4.close();
}
catch(Exception ee)
{
System.out.println("call p_setDetailList3 is wrong:"+ee);
}
}
String cMonth=d1.substring(5,7);
//当月改变时清除当月的计数,并计数当月第一个浏览者.
if(!(cMonth.equals(tMonth)))
{
application.setAttribute(counterSite+"_R_THIS_MONTH_SUM",new Integer(0));
application.setAttribute(counterSite+"_R_COUNT_DATE",new String(d1));
}
//刷新率 end----------------------------------
System.out.print(ee+""+new java.util.Date());
}
ResultSet rs=null;
application.setAttribute(counterSite+"Date1",new java.util.Date());//站点定时时间
sql="select id,R_TODAY_SUM,R_TOM_SUM,R_THIS_MONTH_SUM,R_TOTAL_SUM,R_TOTAL_DAY,R_COUNT_DATE from inber_count_account where ACCOUNT_SIT_ADD like '%"+counterSite+"%'";
//out.print(sql);
rs=stmt.executeQuery(sql);
if(rs.next())
{
application.setAttribute(counterSite+"_checkAccount",new String("ok"));
application.setAttribute(counterSite+"_id",new Integer(rs.getInt(1)));
application.setAttribute(counterSite+"_R_TODAY_SUM",new Integer(rs.getInt(2)));
application.setAttribute(counterSite+"_R_TOM_SUM",new Integer(rs.getInt(3)));
application.setAttribute(counterSite+"_R_THIS_MONTH_SUM",new Integer(rs.getInt(4)));
application.setAttribute(counterSite+"_R_TOTAL_SUM",new Integer(rs.getInt(5)));
application.setAttribute(counterSite+"_R_TOTAL_DAY",new Integer(rs.getInt(6))); //****
application.setAttribute(counterSite+"_R_COUNT_DATE",new String(rs.getString("R_COUNT_DATE"))); }
rs.close();
stmt.close();
}
else
{
if((application.getAttribute(counterSite+"_checkAccount").toString()).equals("ok"))//校验此计数器账号引用是否存在
{
Date accessTime=null;
//刷新率 start---------------------------------- application.setAttribute(counterSite+"_R_TODAY_SUM",new Integer(Integer.parseInt((application.getAttribute(counterSite+"_R_TODAY_SUM").toString()))+1));
application.setAttribute(counterSite+"_R_THIS_MONTH_SUM",new Integer(Integer.parseInt((application.getAttribute(counterSite+"_R_THIS_MONTH_SUM").toString()))+1));
application.setAttribute(counterSite+"_R_TOTAL_SUM",new Integer(Integer.parseInt((application.getAttribute(counterSite+"_R_TOTAL_SUM").toString()))+1));
String d2=application.getAttribute(counterSite+"_R_COUNT_DATE").toString();
//当日期改变时,清除当天的计数
String tYear,tMonth,tDay;
tYear=d2.substring(0,4);
tMonth=d2.substring(5,7);
tDay=d2.substring(8,10); if(!(d1.equals(d2)))
{
int todaysum=Integer.parseInt((application.getAttribute(counterSite+"_R_TODAY_SUM").toString()));
int totalday=Integer.parseInt((application.getAttribute(counterSite+"_R_TOTAL_DAY").toString()));
application.setAttribute(counterSite+"_R_TOM_SUM",new Integer(todaysum));
application.setAttribute(counterSite+"_R_TODAY_SUM",new Integer(0));
application.setAttribute(counterSite+"_R_TOTAL_DAY",new Integer(totalday+1));
application.setAttribute(counterSite+"_R_COUNT_DATE",new String(d1));
try{
CallableStatement cstmt4=null;
pString = "{call p_setDetailList3('"+tYear+"', '"+tMonth+"', '"+tDay+"',"+todaysum+", '"+d2+"',"+Integer.parseInt((application.getAttribute(counterSite+"_id").toString()))+")}";
cstmt4=con.prepareCall(pString);
cstmt4.executeUpdate();
cstmt4.close();
}
catch(Exception ee)
{
System.out.println("call p_setDetailList3 is wrong:"+ee);
}
}
String cMonth=d1.substring(5,7);
//当月改变时清除当月的计数,并计数当月第一个浏览者.
if(!(cMonth.equals(tMonth)))
{
application.setAttribute(counterSite+"_R_THIS_MONTH_SUM",new Integer(0));
application.setAttribute(counterSite+"_R_COUNT_DATE",new String(d1));
}
//刷新率 end----------------------------------
解决方案 »
- 怎样让所有线程都共用一个list?
- 大哥大姐为什么以下代码运行时总是提示没主方法,久候佳音
- No result defined for action kaiqi.goods.actions.GoodsAction and result input -
- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]将截断
- 求救:ireport和jasperreports的问题
- eclipse3.0.1+tomcat5.0.28下编译jsp的问题请教
- 这句话是什么意思"You must have javascript and cookies turned on to access these downloads."
- j2ee安装?安装后设置好后,不能启动server?
- JBuild8升级到Struts1.1......
- 在部署jbuilder7自带例子ESiteWL下esite到weblogic7下时报错如下!请大虾帮忙
- 请问ant支持C/C++构建吗?
- 先问下朋友们,我明年想去上海做JAVA,不知道可以值几个银子啊!
//count=Integer.parseInt((application.getAttribute(counterSite).toString()));
////////////////////////////////////////////定时写数据库同时 初始化数据 start/////////
Date time2=new java.util.Date();//获得系统当前时间
Date t1=(Date)application.getAttribute(counterSite+"Date1");
int secondValue=(int)(((double)time2.getTime()-(double)t1.getTime())/1000);
if(secondValue>=WRITE_TIME)//
{//定时写数据库同时 初始化数据
int siteid=Integer.parseInt((application.getAttribute(counterSite+"_id").toString()));
int a1=Integer.parseInt((application.getAttribute(counterSite+"_R_TODAY_SUM").toString()));
int a2=Integer.parseInt((application.getAttribute(counterSite+"_R_TOM_SUM").toString()));
int a3=Integer.parseInt((application.getAttribute(counterSite+"_R_THIS_MONTH_SUM").toString()));
int a4=Integer.parseInt((application.getAttribute(counterSite+"_R_TOTAL_SUM").toString()));
int a5=Integer.parseInt((application.getAttribute(counterSite+"_R_TOTAL_DAY").toString()));
String a6=application.getAttribute(counterSite+"_R_COUNT_DATE").toString();
try{
CallableStatement cstmt5=null;
pString = "{call p_INBER_COUNT_ACCOUNT_EDIT2("+siteid+","+a1+","+a2+","+a3+","+a4+","+a5+",'"+a6+"')}";
cstmt5=con.prepareCall(pString);
cstmt5.executeUpdate();
cstmt5.close();
}
catch(Exception ee)
{
System.out.println("call p_INBER_COUNT_ACCOUNT_EDIT2 is wrong:"+ee);
}
//count=0;
//application.setAttribute(counterSite,new Integer(count));//得到初始值,
application.setAttribute(counterSite+"Date1",new java.util.Date());//初始时间为系统当前时间
//application.setAttribute(counterSite,new Integer(count));//计数器
////////////////////////////////////////////定时写数据库同时 初始化数据 end//////////////////
}
//////////////检验数据2开始///////////////////////////////////////////////////////////
/*out.print("secondValue="+secondValue+"<BR>");
out.print("counter="+count+"<BR>"+"counterSite="+counterSite+"<BR>");
*/
//////////////检验数据2结束///////////////////////////////////////////////////////////
}
else
{//校验此计数器账号引用是否存在
}
} //System.out.println(count+":"+counterSite+" "+theIP);
// count++;
//application.setAttribute(counterSite,new Integer(count));
} catch(SQLException e)
{
System.out.println("cc:"+e);
} out.close();
}
/**
*处理Post请求
*/ /**
*获得初始化参数
*/
public void init() throws ServletException
{
try{
int ss=0;
con=DataBaseConnection.getConnection();
}
catch (Exception e)
{ System.out.println("Error(con error):"+e);
}
}
public void destroy()
{
int siteid=Integer.parseInt((application.getAttribute(counterSite+"_id").toString()));
int a1=Integer.parseInt((application.getAttribute(counterSite+"_R_TODAY_SUM").toString()));
int a2=Integer.parseInt((application.getAttribute(counterSite+"_R_TOM_SUM").toString()));
int a3=Integer.parseInt((application.getAttribute(counterSite+"_R_THIS_MONTH_SUM").toString()));
int a4=Integer.parseInt((application.getAttribute(counterSite+"_R_TOTAL_SUM").toString()));
int a5=Integer.parseInt((application.getAttribute(counterSite+"_R_TOTAL_DAY").toString()));
String a6=application.getAttribute(counterSite+"_R_COUNT_DATE").toString();
try{
CallableStatement cstmt6=null;
pString = "{call p_INBER_COUNT_ACCOUNT_EDIT2("+siteid+","+a1+","+a2+","+a3+","+a4+","+a5+",'"+a6+"')}";
cstmt6=con.prepareCall(pString);
cstmt6.executeUpdate();
cstmt6.close();
System.out.println("when the programe stoped execute this code automatic!");
con.close(); }
catch (SQLException e)
{ System.out.println("desdory error:"+e);
}
}
}
2. 对象上注意是否线程安全, 避免多个线程同时写变量
3. 更新数据使用相对值, 不要用绝对值. 如: update table set a = a + @value where ...100000/天访问不算大, 如果没有并发峰值限制. 不需要太特殊得处理方法
对于我这个单程的程序如何解决并发访问问题?
如果我改用Weblogic是不是它可以在并发问题上有所处理?