简体   繁体   English

Java线程池执行器

[英]Java Thread Pool Executor

I am doing a reminder application. 我正在做一个提醒应用程序。

I have the jobs in the priority queue. 我的工作在优先队列中。

The sample job object is {job_id : 1001, epoch : 1514140200000} . 样本作业对象是{job_id : 1001, epoch : 1514140200000}

The task is to make the job execute in that epoch time. 任务是使作业在那个时期内执行。

I am planning to dequeue a job from the queue and assign a thread to it and schedule it to run in that epoch time. 我打算从队列中取出一个作业,并为其分配一个线程,并安排它在那个时代运行。 Is there a way to do it or is that the correct way to do? 有办法做到还是正确的做法?

If you want to do this via Java thread pools, see the ScheduledExecutorService: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html . 如果要通过Java线程池执行此操作,请参见ScheduledExecutorService: https : //docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html

That has a nice sample, but basically you can schedule tasks to run at particular times or after a particular delay. 那是一个很好的示例,但是基本上您可以安排任务在特定时间或特定延迟后运行。

Libraries like Quartz (as someone notes) provide lots of other options. 像Quartz这样的库(正如有人指出的那样)提供了许多其他选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM