Question

I have used Spring TaskExecutor with a ThreadPoolTaskExecutor implementation to implement an asynchronous queue with a thread pool. The objects being stored on the queue are small JSONObjects (40 bytes max) but the number of objects will be quite large, up to 100,000.

A new requirement has now been placed on us to make this queue persistent so that it can survive a JVM/server restart. Is there an efficient way to persist this queue reusing the above implementation and without introducing too much complexity into my application? Is there something in the TaskExecutor configuration itself that I can use to achieve this aim or do I have to resort to something else, like JMS, or a custom solution, such as writing to a file?

Any help/ideas will be greatly appreciated.

Was it helpful?

Solution

The ThreadPoolTaskExecutor only works with Runnable objects, thus it has no concept of objects that are serializable that happen to be processed in a runnable.

If you need to persist the objects, you will need to do this before you execute, and then have a service that resubmits them after a restart. If you want to mark the execution completed, either your runnable can remove the persistence at the end of it's process, or you can use the submit method on the ThreadPoolTaskExecutor and monitor the Future.

It would also be possible to write an advisor that you can place on the TaskExecutor (since it is likely a spring managed bean in your case), and implement the persisting logic there as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top