0

I would like to implement a consumer service which is processing tasks from a queue. The consumer service / task runner I have implemented using an executor service.

However some of the tasks I need to process take longer than others and I would like to implement some type fairness within the task runner. When i invoke/schedule the consumer I will know the number tasks presently on the queue to execute.

I was wondering what is the best approach to achieve this ?

Each task has a specific type and an approx execution time.

Mojo
  • 1
  • 3

1 Answers1

0

You can adjust resource usage by experimenting with task priorities or you can force the longer-running tasks to periodically sleep, forcing them to allow other tasks to execute.

Jim Rogers
  • 4,822
  • 1
  • 11
  • 24
  • Yes a priority queue would go far to solve this. My problem is that my service is subscribed to external service publishing tasks per user on queue. To achieve the priority scheduling would I need to pop tasks off the subscribed queue, place in priority queue and then submit to executor service ... introducing another queue just does not seem correct to me. – Sam Nov 28 '18 at 20:42