Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何对无限循环java nio watchservice程序进行基准测试_Java_Benchmarking - Fatal编程技术网

如何对无限循环java nio watchservice程序进行基准测试

如何对无限循环java nio watchservice程序进行基准测试,java,benchmarking,Java,Benchmarking,我有一个无限轮询循环,使用java.nio.file.WatchService查找新文件。在这个循环中,我有一个固定的线程池执行器服务来并发处理文件 当轮询服务持续运行时,我如何对批处理(比如10/n个文件)所用的时间进行基准测试。我可以对可运行类中的每个文件计时,但如何获得批处理时间?类似的方法应该可以工作: // inside the listener for the WatchService final MyTimer t = new MyTimer(); // takes current

我有一个无限轮询循环,使用java.nio.file.WatchService查找新文件。在这个循环中,我有一个固定的线程池执行器服务来并发处理文件


当轮询服务持续运行时,我如何对批处理(比如10/n个文件)所用的时间进行基准测试。我可以对可运行类中的每个文件计时,但如何获得批处理时间?

类似的方法应该可以工作:

// inside the listener for the WatchService
final MyTimer t = new MyTimer(); // takes current time, initialized to 0 tasks
for (Change c : allChanges) {
   t.incrementTaskCount(); // synchronized
   launchConcurrentProcess(c, t);
}

// inside your processor, after processing a change
t.decrementTaskCount(); // also synchronized

// inside MyTimer
public void synchronized decrementTaskCount() {       
   totalTasks --;

   // depending on your benchmarking needs, you can do different things here
   // I am printing max time only (= end of last), but min/max/avg may also be nice
   if (totalTasks == 0) {
      System.err.println("The time spent on this batch was " 
          + System.currentTimeMillis() - initialTime);
   }
}

您需要将一个传统的“state holding”对象传递给批处理的所有部分,然后在它们全部完成时计算基准。如果没有这个附加对象,你无法知道它们是否都完成了,特别是是否有新的东西出现了。他们说现代超级计算机在三秒钟内完成了无限循环。