I have the next project:
Spring(3.2)-based Web application(Tomcat 7), in background I have several tasks.
I have a queue with some information for processing. This queue is updating periodically(but just when it empty).
Also I have several threads that enqueue periodically data from this queue and process.
For scheduling I wanted to use ScheduledExecutorService.
I have several problems\\questions:
How to keep this queue? As I think it should be global. Should I make it static in some "holder" class? Won't be this a poor desing?
Where will be the good place for initializing this queue and all the task with ScheduledExecutorService? Is ServletContextLoadingListener a good place for it? Are there any ways to init this with Spring?
Should I use several ScheduledExecutorService instances if I need to control the number of consumer threads exactly?
Will ArrayBlockingQueue be good for this case?
singleton
. init-method
in spring configuration or implement the InitializingBean
interface in your class. ScheduledExecutorService
is configurable via the constructor arguments. If you have tasks of several types and want to run them in separate thread pools, you can use multiple ScheduledExecutorService
instances. However, if all your task are of the same type, I don't see the need for multiple ScheduledExecutorService
instances. ScheduledThreadPoolExecutor
provided within JDK has an internal working queue of class java.util.concurrent.ScheduledThreadPoolExecutor.DelayedWorkQueue.DelayedWorkQueue
(and it is not configurable). I am not sure where do you put the ArrayBlockingQueue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.