使用ExecutorService计划的任务

我想在JAVA中使用ExecutorService来安排每5分钟插入数据库。 这是我想要执行它的任务:

  MyClass{ a counter that count a handled data received from a Thread I receive usually 300 data line/second Apply a treatment on these data and keep the results in the memory every five minutes { update the database with the counters saved in memory* } } 

基本上,每当他从后台运行的线程获取数据时,它就会调用该任务。 因为我有超过300个数据/秒,所以不可能以这种方式使用它。

所以我正在尝试做id来处理收到的任务并在内存中保留一个计数器并且每5分钟更新一次数据库。

我的问题是,是否可以使用这些java函数ScheduledExecutorService来做到这一点,我们怎么做呢(我不想在任务上阻止我的JAVA应用程序5分钟,我希望该应用程序正常运行但不执行每次都有任务,如果你能告诉我一些这些function的用法,我很感激吗?

 ScheduledExecutorService service = Executors.newScheduledThreadPool(1); service.scheduleAtFixedRate(command, 5, 5, TimeUnit.MINUTES); 

其中command是:

 Runnable command = new Runnable() { public void run() { // update database } }