在JSP页里面有个JAVA小程序,运行一段时间后整个电脑屏幕都得得很花了,最右下角的时间都跑屏幕的最左上角去了,这时整个屏幕一片灰色,请问这是怎么回事来着在小程序里有个SOCKET在不停的收消息

解决方案 »

  1.   

    在JSP页面上是
              <tr>
               <td>
              
               <iframe src="telephone.jsp" width=100% marginwidth="0" height=65 marginheight="0" scrolling="no" frameborder=0></iframe>
              
               </td>
              </tr>小应用程序里的一段代码
    public void run() {
    InputStreamReader reader = null;
    while(true) { if(Thread.currentThread() == thread) {
    if(agentNo== null ||agentNo.trim().length() == 0 || phoneGroup == null || phoneGroup.trim().length() == 0 || phoneLevel == null || phoneLevel.trim().length() == 0 || showName == null || showName.trim().length() == 0) {
    System.out.println("不做任何错误.等待值传入..");
    } else {
    if(s != null || !s.isClosed()) {
    if(!loginFlag) {
    OutputStream os = null;
    try {
    os = s.getOutputStream();
    StringBuffer sb = new StringBuffer();
    sb.append("LOGIN");
    sb.append("%");
    sb.append(agentNo);
    sb.append("%");
    sb.append(showName);
    sb.append("%");
    sb.append(phoneGroup);
    sb.append("%");
    sb.append(phoneLevel);
    os.write(sb.toString().getBytes());
    os.flush();
    loginFlag = true;
    System.out.println("发送登陆信息........");
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    } else {

    }
    }

    if(s == null) {
    System.out.println("Socket等于空");
    } else {
    if(s != null || !s.isClosed()) {
    if(loginFlag) {
    try {
    reader = new InputStreamReader(s.getInputStream());
    char[] c = new char[2048];
    if(reader.ready()) {
    reader.read(c, 0, c.length);
    }
    if(new String(c).trim().length() > 0) {
    //System.out.println("服务器返回 "+new String(c).trim());
    processServerMessage(new String(c).trim());
    }
    Thread.sleep(5);
    } catch (InterruptedException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    }

    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    }
    }
      

  2.   

    应该不是SOCKET问题吧~~你把线程停掉再试下
      

  3.   

    把线程停掉了也是那样,不过好像坚持得久一点了,一开始只是页面在乱闪,电脑还能操作,再过一段时间后,整个屏幕都开始乱闪了,这时什么都不能弄了,按Alt+F4键倒是能把页面关掉,这时又恢复正常了
      

  4.   

    更郁闷的是在有Eclipse的机器上就不出那种现象,新找一台机器把SDK装上,再打开那个JSP页面后就是那种效果 :(
      

  5.   

    Thread.sleep(5);把这个改的大一些试试Thread.sleep(2000)
      

  6.   

    我认为这个问题是由于采用了THREAD才产生的问题,THREAD不断的刷新着你的SWING或者APPLET,电脑屏幕也就不断的在刷新输出,你看看用其他方法代替掉SYSTEM.OUT.PRINT这种方法,使小程序尽量不要一直刷新屏幕
      

  7.   

    问题解决了,谢谢大家的热心帮助,不是程序问题,是在JSP页面上有个滚动着的消息,是那个导致的,谢谢大家了:)