return null;//这里会返回方法调用这句应该永远执行不到

解决方案 »

  1.   

    楼上:
    public MsgReply waitToReply(String mid) throws JMSException
      {
        long begin = System.currentTimeMillis();
        begin += 60000;
        while (begin > System.currentTimeMillis())
        {
          synchronized (messages)
          {
            try
            {
              //System.out.println("Session waitToReply() messages.wait()");
              messages.wait();
              for (int i = 0; i < messages.size(); i++)
              {
                Object obj = messages.get(i);
                if (obj instanceof MsgReply)
                {
                  if ( ( (MsgReply) obj).GetCorrelationID().equals(mid))
                  {
                    messages.removeElement(obj);
                    return (MsgReply) obj;
                  }
                }
              }
            }
            catch (InterruptedException e)//当捕获一个这样的异常时
            {
              throw new JMSException("break Exception!");//这里不返回方法调用,只结束本次循环,接着进入下次循环        }
          }    }
        throw new JMSException("timeout while waiting for server reply");  }
      

  2.   

    public MsgReply waitToReply(String mid) throws JMSException
      {
        long begin = System.currentTimeMillis();
        begin += 60000;
        while (begin > System.currentTimeMillis())
        {
          synchronized (messages)
          {
            try
            {
              //System.out.println("Session waitToReply() messages.wait()");
              messages.wait();
              for (int i = 0; i < messages.size(); i++)
              {
                Object obj = messages.get(i);
                if (obj instanceof MsgReply)
                {
                  if ( ( (MsgReply) obj).GetCorrelationID().equals(mid))
                  {
                    messages.removeElement(obj);
                    return (MsgReply) obj;
                  }
                }
              }
            }
            catch (InterruptedException e)//当捕获一个这样的异常时
            {
             public MsgReply waitToReply(String mid) throws JMSException
      {
        long begin = System.currentTimeMillis();
        begin += 60000;
        while (begin > System.currentTimeMillis())
        {
          synchronized (messages)
          {
            try
            {
              //System.out.println("Session waitToReply() messages.wait()");
              messages.wait();
              for (int i = 0; i < messages.size(); i++)
              {
                Object obj = messages.get(i);
                if (obj instanceof MsgReply)
                {
                  if ( ( (MsgReply) obj).GetCorrelationID().equals(mid))
                  {
                    messages.removeElement(obj);
                    return (MsgReply) obj;
                  }
                }
              }
            }
            catch (InterruptedException e)//当捕获一个这样的异常时
            {         return null;        }
          }    }
        throw new JMSException("timeout while waiting for server reply");  }
            }
          }    }
        throw new JMSException("timeout while waiting for server reply");  }
      

  3.   

    public MsgReply waitToReply(String mid) throws JMSException
      {
        long begin = System.currentTimeMillis();
        begin += 60000;
        while (begin > System.currentTimeMillis())
        {
          synchronized (messages)
          {
            try
            {
              //System.out.println("Session waitToReply() messages.wait()");
              messages.wait();
              for (int i = 0; i < messages.size(); i++)
              {
                Object obj = messages.get(i);
                if (obj instanceof MsgReply)
                {
                  if ( ( (MsgReply) obj).GetCorrelationID().equals(mid))
                  {
                    messages.removeElement(obj);
                    return (MsgReply) obj;
                  }
                }
              }
            }
            catch (InterruptedException e)//当捕获一个这样的异常时
            {
              return null;
            }
          }    }
        throw new JMSException("timeout while waiting for server reply");  }
      

  4.   

    都出现异常了,还要程序执行阿??你还顾不顾我们的computer的命了?:)
      

  5.   

    哈!: zhang21cnboy(事了抚衣去,不留身与名)老兄搞笑。
      

  6.   

    注意!我是指同一处(上面代码捕获异常时)的以下两种处理方法,注释的理解对吗?
    1.throw new JMSException("break Exception!");//这里不返回方法调用,只结束本次循环,接着进入下次循环

    2.return null;//这里会返回方法调用
      

  7.   

    不会,俺就尝试,给你解释一下java的异常机制。之所以叫做异常,就说明如果不处理这个异常,那么程序就没有办法继续执行了!也就是说,当你在你的那个方法里面throw new JMSException("break Exception!");的时候,你调用宿主的try catch会吗上做出反应的。那么是什么样的反映呢?当程序try到异常的时候,就会终止和清除try中的所有调用,然后转到catch快执行。那么你可以想,当你的throw new JMSException("break Exception!");以后,你的那个循环还能继续执行么?
      

  8.   

    throw就表示出错了,return就是返回而已