title: Java Code for Calculating Packet Per Second
body: <p>I have method that receives packets from switch to floodlight controller in SDN which is mean this method is triggered for every new coming packet. I want to calculate the packet per second in that method.</p>
  
  <p>This is my attempt; it is correct? </p>
  
  <pre><code>int CLoad,avergeLoad =0;
  final String switchId = sw.getStringId();
          CLoad = CLoad + 1;
          avergeLoad = CLoad;
          loadTable.put(switchId, avergeLoad);
          ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
          exec.scheduleAtFixedRate(new Runnable() 
                 {
                  public void run() 
                    {
                      avergeLoad =(avergeLoad + CLoad)/2;
                  loadTable.put(switchId, avergeLoad);
                     CLoad=0;
                    }
                 }, 40, 1000, TimeUnit.SECONDS); 
  </code></pre>