【问题标题】:Calculate the response time for JMS messages计算 JMS 消息的响应时间
【发布时间】:2012-08-09 13:23:53
【问题描述】:

处理一个使用 5 个线程将 1000 条 JMS 消息发布到 EMS 服务器的 Java 应用程序。我有一个迭代 5 次的循环,并且在每个循环中我启动一个可运行的线程来发布 200 条消息。

如何计算每条消息的响应时间?以及每个线程的响应时间(200 条消息)?

【问题讨论】:

    标签: java multithreading queue jms


    【解决方案1】:

    您可以使用 currentTimeMillis 方法并以这种方式计算时间:

        long time1=System.currentTimeMillis();
    
        //Send 200 JMS Msg loop        
            long timeIntern1=System.currentTimeMillis();
            //Send a JMS Msg       
            long timeIntern2=System.currentTimeMillis();
            System.out.println("Time in millis last JMS Msg: "+(timeIntern2-timeIntern1));
    
        long time2=System.currentTimeMillis();
    
        System.out.println("Total time in millis: "+(time2-time1));
    

    【讨论】:

      【解决方案2】:

      您可以使用 Date.getTime() 方法:

      import java.util.Date;
      
      static long stamp()
      {
          return new Date().getTime();
      }
      
      public static void main(String[] args) throws InterruptedException
      {
          long start = stamp();
          //Do whatever
          Thread.sleep(5_124);
          long end = stamp();
          System.out.println("Took " + (end - start) + " milliseconds.");
      }
      

      输出:

       Took 5124 milliseconds.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-11-16
        • 1970-01-01
        • 2022-01-06
        • 2015-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多