最近用DWR开发一个AJAX生产上应用的程序,刚开始使用时WEB页面CALL JAVA代码可以正常返回信息,而且速度很快,但是使用一段时间后返回信息的时间变慢,甚至有时会出现没有返回信息的状态。
不知各位有没有遇到相关问题,是如何解决的?请赐教,谢谢!

解决方案 »

  1.   

    可能是你用hibernate没有配置好, session 没有关闭.
      

  2.   

    你们所说这些都没有问题,我用的是JDBC,每个一个SESSION只有一个DB连接,当SESSION关闭时通过侦听结束事件来DB的连接。
      

  3.   

    用debug模式调试, 看卡哪一步了.
      

  4.   

    在本机运行正常,但是提交SERVER上运行一段时之后就会出现这样的问题,相当的郁闷啊,有谁能帮我解决啊
      

  5.   

    以下是运行时的LOG,帮忙看看有什么问题?DWR 15:24:54,268 moting.dwrp.BaseCallMarshaller DEBUG Environment:  c0-e4=string:, c0-e1=string:Z579305550, c0-e3=string:MOVE, c0-e2=string:2D-1-A2, 
    DWR 15:24:54,269 emoting.extend.TypeHintContext DEBUG Using type info from <signature> moveLocation(0<0>) of class java.lang.String
    DWR 15:24:54,269 emoting.extend.TypeHintContext DEBUG Using type info from <signature> moveLocation(0<1>) of class java.lang.String
    DWR 15:24:54,269 ebremoting.impl.DefaultRemoter  INFO Exec: hostservice.moveLocation()
    DWR 15:24:54,269 ebremoting.impl.DefaultRemoter DEBUG --Object found in application. id=0
    parse reply start .......[S0LOCATION_REP HDR=(S2MOD.HT.TRACKING,MOD.WEB20090728032454.24)  REPLYSTATUS=FAIL ERRORCODE=16 ERRORMSG="reasonCode = 100: PRE-CHECK CODE := 100 ERROR := boxidP592950426 is not active ! ; ruleReply = CANCELRULE"]
    parse reply end .......[]
    03632299 reply to client!
    DWR 15:24:54,577 ting.util.DebuggingPrintWriter DEBUG out(4980): //#DWR-INSERT
    DWR 15:24:54,577 ting.util.DebuggingPrintWriter DEBUG out(4980): //#DWR-REPLY
    DWR 15:24:54,577 ting.util.DebuggingPrintWriter DEBUG out(4980): dwr.engine._remoteHandleCallback('4','0',{ERRORCODE:"16",REPLYSTATUS:"FAIL",ERRORMSG:"\"reasonCode= 100: PRE-CHECK CODE := 100 ERROR := boxidP592950426 is not active ! ; ruleReply = CANCELRULE\""});
      

  6.   

    可以的,如果你用的是ORACLE可以查看v$session视图中的内容,测试时你可以将SESSION的有效期设短一点,然后在WEB SERVER里增加listener来侦听SESSION结束事件,在SESSION结束事件里将其DB连接关闭就可以
      

  7.   

    这不会的,这种类型的事件,是SERVER级,你可以了解一下SESSION开始和结束事件。
    这个不是问题,经过我的N次测试,既使出现了这样的问题,我可以将DATA SOURCE可连接数设置很大很大,
    我提供LOG的那一段调用不是DB部份,是我们APP SERVER部分,从APP SERVER也正常返回给WEB SERVER,但是从WEB SERVER返回给CLIENT端出现了问题,出现了问题之后将WEB SERVER重启之后用一段时间之后又出现同样的问题/
      

  8.   

    你为什么不放在监听request结束的时候关闭数据库连接?此内问题大多是数据库连接未关闭造成的。
      

  9.   

    不是的,我上面所说的查询数据库方面都没有问题,就是CALL 我们应用服务器上的内容时出现的问题,
    如果每次REQUEST时都关闭或打开DB连接,那次次数太频繁,会造成新的性能问题,REQUEST结束并意味着过几分在没有REQEST了。
      

  10.   

    可能处理数据比较多,也可能网络速度你看下查询语句是否得优化下。
    http://www.java1995.org/ JAVA学习网站 
      

  11.   

    以下代码红色部分是使用一段时间会出问题的部分:function locationInSubmit(){    
    if (loginUser==""){
        alert("你还没登录,请登录!")
        return;
    }

    if (document.form1.txtlocation.value==""){
        alert("请输入LOCATION!");
    document.form1.txtlocation.focus();
    return;
    }

    if (document.getElementById("labMaxqty").innerHTML==""){
        alert("LOCATION信息有问题,输入LOCATION后请按回车!");
    document.form1.txtlocation.focus();
    return;
    }

        if (document.form1.txtpallet.value==""){
        alert("请输入LOCATION!");
    document.form1.txtpallet.focus();
    return;
    }

    if (document.getElementById("labproduct").innerHTML==""){
        alert("PALLETID信息有问题,输入LOCATION后请按回车!");
    document.form1.txtpallet.focus();
    return;
    } var v_orderNo="";
       
    if (document.all.trOrder.style.display=="block"){
    if (document.all.orderReqQty.innerHTML==""){
    alert(document.all.txtOrder.value+"的OUT信息没有得到,输入ORDERNO请按回车!");
    document.all.txtOrder.focus();
    return;
    } v_orderNo= document.all.txtOrder.value;
    }

    var request={
           LOTSET:document.form1.txtpallet.value,
       LOCATIONID:document.form1.txtlocation.value,
       ACTIVITY:"MOVE",
       ORDERNO:v_orderNo  
    }; //alert(request.ORDERNO);
     
    //hostservice.moveLocation(request,callpass);
    hostservice.moveLocation(request,
                   {callback:function(str) {callBackSubmit(str); },
                 timeout:30000,
                 errorHandler:function(message) { alert( message); }
            });
    //LoginHtml(document.form1.txtUserid.value,document.form1.txtPasswd.value,floorValue);
    }function callBackSubmit(data){    
        if (data.REPLYSTATUS=="FAIL") {
         alert("失败["+data.ERRORMSG+"]");
    }else{
        alert(data.REPLYSTATUS);
    }
    fromClear();

    }
      

  12.   

    以下是对应的JAVA代码(movelocation):public Map moveLocation(Map map,HttpSession sess){
    HashMap replyMap=new HashMap();
    User user=(User)sess.getAttribute("USER");

    if (user==null){
    replyMap.put("REPLYSTATUS", "FAIL");
    replyMap.put("ERRORMSG", "你没有登录,请登录!");
    return replyMap;
    }

    map.put("USERID", user.getUserId());

    TibMessageSendReply tib=new TibMessageSendReply(user,"S0LOCATION");
    try{
        tib.sendMessage(map);
    }catch(Exception e){
    replyMap.put("REPLYSTATUS", "FAIL");
    replyMap.put("ERRORMSG", e.getMessage());
    tib=null;
    return replyMap;
    }
    replyMap=(HashMap)tib.getReply();
    //tib=null;
    System.out.println(user.getUserId()+" reply to client!");
    return replyMap;
    }
      

  13.   

    以下是对应的TibMessageSendReply的内容:
    package pda.common;import java.util.Date;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Random;
    import java.util.Set;import com.tibco.tibrv.Tibrv;
    import com.tibco.tibrv.TibrvException;
    import com.tibco.tibrv.TibrvListener;
    import com.tibco.tibrv.TibrvMsg;
    import com.tibco.tibrv.TibrvMsgCallback;
    import com.tibco.tibrv.TibrvRvdTransport;
    import com.tibco.tibrv.TibrvTransport;public class TibMessageSendReply {
     private String service = null;
     private String network = null;
     private String daemon  = null;
     private String subJect = null;
     private String replySubject=null;
     private String cmd=null;
     
     private String FIELD_NAME = "DATA";
     private String sendSubect ="HT.TRACKING";
     private boolean runing=false;
     
     private Map replyResult;
     
     public Map getReply(){
     return replyResult;
     }
     
     public TibMessageSendReply(String service,String network,String daemon,String subject,String cmd){
     this.service=service;
     this.network=network;
     this.daemon=daemon;
     this.subJect=subject;
     this.cmd=cmd;
     replyResult=new HashMap();
     }
     
     public TibMessageSendReply(User user,String cmd){
     this.service=user.getTibService();
     this.network=user.getTibNetwork();
     this.daemon=user.getTibDaemon();
     this.subJect=user.getTibSubject();
     this.cmd=cmd;
     replyResult=new HashMap();
     }
     
     private String paseMessage(Map message){     
     Random random = new Random();
     replySubject="MOD.WEB"+
                  (new java.text.SimpleDateFormat("yyyyMMddhhmmss")).format(new Date())+
                  "."+random.nextInt(100);
     
     String sMessage="HDR=("+this.subJect+"."+this.sendSubect+","+replySubject+")";
     
     Set entries=message.entrySet();
     Iterator iter=entries.iterator();
     while(iter.hasNext()){
     Map.Entry entry=(Map.Entry)iter.next();
     String key=(String)entry.getKey();
     String value=(String)entry.getValue();
     sMessage=sMessage+" "+key+"="+value;
     }
     return sMessage;
     }
     
     public void sendMessage(Map message) throws Exception{
      try{
                Tibrv.open(Tibrv.IMPL_NATIVE);
          }catch (TibrvException e) {
                System.err.println("Failed to open Tibrv in native implementation:");
                throw new Exception("Failed to open Tibrv in native implementation:");
          }
          
          TibrvTransport transport = null;
          try  {
                transport = new TibrvRvdTransport(this.service,this.network,this.daemon);
          } catch (TibrvException e) {
                System.err.println("Failed to create TibrvRvdTransport:");
                throw new Exception("Failed to create TibrvRvdTransport:"); 
          }
          
          TibrvMsg msg = new TibrvMsg();         
          try{
                msg.setSendSubject(this.subJect+"."+sendSubect);
          } catch (TibrvException e) {
                System.err.println("Failed to set send subject:");
                throw new Exception("Failed to set send subject:"); 
          }
          
          String sMessage=cmd+" "+paseMessage(message);
          
          runing=true;
          
          //Tibrvlisten tibListen=new Tibrvlisten();       
          try{
           System.out.println("Publishing: subject="+msg.getSendSubject()+
                                " \""+sMessage+"\"");
               msg.update(FIELD_NAME,sMessage);
               
               transport.send(msg);           
           }catch (TibrvException e){
                System.err.println("Error sending a message:");
                throw new Exception("Error sending a message:"); 
            }
           Tibrvlisten tibListen=new Tibrvlisten();        
          
           while(runing);         // Close Tibrv, it will cleanup all underlying memory, destroy
            // transport and guarantee delivery.
            try
            {
                Tibrv.close();
            }
            catch(TibrvException e)
            {
                System.err.println("Exception dispatching default queue:");
                throw new Exception("Exception dispatching default queue:");  
            }
     }
     
     private class  Tibrvlisten implements TibrvMsgCallback{  
       
     public Tibrvlisten() throws Exception{
     try{
                Tibrv.open(Tibrv.IMPL_NATIVE);
         } catch (TibrvException e){
                System.err.println("Failed to open Tibrv in native implementation:");
                throw new Exception("tiblistne open[Failed to open Tibrv in native implementation:]"); 
         }
         
         TibrvTransport transport = null;
         try{
          System.out.println("service="+service+",network="+network+",daemon="+daemon);
          
          transport = new TibrvRvdTransport(service,network,daemon);
         } catch (TibrvException e){
                System.err.println("Failed to create TibrvRvdTransport:");
                throw new Exception("tiblistne open[Failed to create TibrvRvdTransport:]"); 
         }
         
         try{
                    new TibrvListener(Tibrv.defaultQueue(),
                                this,transport,subJect+"."+replySubject,null);
                    System.err.println("Listening on: "+subJect+"."+replySubject);
             } catch (TibrvException e){
                    System.err.println("Failed to create listener:");
                    throw new Exception("tiblistne open[Failed to create listener:]");
             }
             
             int sleepCont=0;
             while(runing)
             {   
                 try
                 {
                     Tibrv.defaultQueue().dispatch();
                 }
                 catch(TibrvException e)
                 {
                     System.err.println("Exception dispatching default queue:");
                     throw new Exception("tiblistne open[Exception dispatching default queue:]");
                 }
                 catch(InterruptedException ie)
                 {
                  throw new Exception("tiblistne open["+ie.getMessage()+"]");
                 }
             }
             
             
             try{
            Tibrv.close();
         }  catch(TibrvException e) {
            System.err.println("Exception dispatching default queue:");
            throw new Exception("Exception dispatching default queue:");  
         }
          
     }
     
     public void onMsg(TibrvListener arg0, TibrvMsg msg) {
    // TODO Auto-generated method stub
     
     replyResult.clear();
     /*
     System.out.println((new Date()).toString()+
                         ": subject="+msg.getSendSubject()+
                         ", reply="+msg.getReplySubject()+
                         ", message="+msg.toString()
                       );
     System.out.flush();*/
     String repStr=msg.toString();
     repStr=repStr.substring(repStr.indexOf(FIELD_NAME)+6, repStr.length()-4).trim();
     System.out.println(repStr);
     //repStr=repStr.replace("\"", "");
     while(repStr.length()>0){  
     int pos=repStr.indexOf(32);
     String key;
     
     if (pos==-1){
     key=repStr;
         repStr="";
     }else {
          key=repStr.substring(0, pos);
          
          int pos1=key.indexOf("\"");
          if (pos1!=-1){
           String tmpStr=repStr.substring(pos+1);
           pos1=tmpStr.indexOf("\"");
           key=key+tmpStr.substring(0,pos1+1);
           repStr=tmpStr.substring(pos1+1);
          }
          else {
               repStr=repStr.substring(pos+1);
          }     
          repStr=repStr.trim();
     }    
     
     if (key.indexOf("=")!=-1){
        String tmpKey=key.substring(0,key.indexOf("="));     if (tmpKey.equals("HDR")) continue;
         String tmpValue=key.substring(key.indexOf("=")+1);
         
         replyResult.put(tmpKey, tmpValue);
         
     } else {
     continue;
     }
     
    // System.out.println(key);
     }
                 
     runing=false;
     }
      }
     
     public static void main(String[] args){
     TibMessageSendReply msgSend=new TibMessageSendReply("7521",";239.109.120.1","7521","S1MOD","PDA");
     HashMap map=new HashMap();
     map.put("USER", "ZLL");
     map.put("LOTID", "ZLL");
     try{
     msgSend.sendMessage(map);
     map=(HashMap)msgSend.getReply();
     
     Set entries=map.entrySet();
     Iterator iter=entries.iterator();
     while(iter.hasNext()){
     Map.Entry entry=(Map.Entry)iter.next();
     String key=(String)entry.getKey();
     String value=(String)entry.getValue();
     System.out.println("key="+key+",value="+value);
     }
     }catch(Exception e){
     e.printStackTrace();
     }  
     }
    }
      

  14.   

    没有关闭session或者什么别的连接没关闭什么的。就能导致DWR做的变慢.