title: Measure response time in java (web service)?
body: <p>I'm trying to measure the response time for a "process" (I'm requesting data from a server and then presenting the data). I want to measure the time it takes from when I ask for the data (when I press the "send" button) to when the data is displayed in my txtbox.</p>
  
  <p>That looks like this:</p>
  
  <pre><code>    (these two are at the very top:)
      private long a
      private long b
  
  
     ...other code...
  
  
      a = System.currentTimeMillis();
  
      btnSend.addActionListener(new ActionListener(){
  
          @Override
          public void actionPerformed(ActionEvent arg0) {
              String fileContents;
              b = System.currentTimeMillis();
              try {
                  fileContents = control.getFileContents(txtSearch.getText());
                  txtView.setText(fileContents + "\n" + "\n" + "The process took "+(b-a)+"milliseconds to execute." + "\n" + "("+((b-a)/1000)+" seconds)");
  
              } catch (RemoteException e) {
                  txtView.setText("File not found");
              }
  
          }
  </code></pre>
  
  <p>Ant it works, but just the first time. If I send another request the time is just added to the old time. The first request takes 2 seconds, and the second it says it took 7 seconds (when in reality it took like 2).</p>
  
  <p>I tried circumventing the problem by reseting a and b by putting:</p>
  
  <pre><code>    a = 0; 
      b = 0;
  </code></pre>
  
  <p>in the reset button, but that only seem to have made things go a bit crazy.</p>
  
  <p>Any thoughts on how to solve the problem?</p>
  
  <p>Thanks</p>