Вопрос

is there a way to pass a BlockingQueue to a job in the Quartz framework? I tried to use the JobDataMap for passing the BlockingQueue but that doesn't seem to work. Here the relevant code fragment:

JobDetail job = newJob(Jobby.class)
  .withIdentity("myJob", "group1")
  .usingJobData("buffer", queue)
  .build();

Perhaps someone has an idea on how to achieve this.

Это было полезно?

Решение

Looks like you are trying to implement producer/consumer design pattern where producers are placing work in a queue and consumer checks that queue periodically using Quartz. This design isn't bad, however your implementation won't work. By passing that queue to the job data Quartz will serialize it and deserialize it back when jobs trigger. The queue won't be passed by reference but by value (copy). This is understandable if you realize that Quartz should work in a distributed environment, where job is scheduled and persisted to the database on one node and deserialized and executed on other node.

That being said you need to reevaluate your implementation. If you don't care about clustering and distribution, make your queue somehow globally available. Your options are:

  • global - please, no
  • resource available via
  • bean injected to both producers and job class (Spring supports Quartz quite well)
  • ...

I specifically recommend using , is also a nice option. But if we are talking about - why not consider using some lightweight implementation instead of Quartz? You would avoid latency.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top