0

I need an ScheduledThreadPoolExecutor that runs Task according there priority. If 2 or more Task a pending for immediate execution the one with the highest priority must be called first.

Actually there is a solution for ThreadPoolExecutor, but not for ScheduledThreadPoolExecutor, cause it provides no constructor with a BlockingQueue argument.

See: Java Executors: how can I set task priority?

Community
  • 1
  • 1
Chriss
  • 4,642
  • 6
  • 35
  • 69

1 Answers1

1

If I were you I'll have a single threaded ScheduledThreadPoolExecutor which posts to a ThreadPoolExecutor with a PriorityBlockingQueue. Not the most elegant, but it'll get the job done.

Enno Shioji
  • 25,972
  • 13
  • 68
  • 108
  • How would you implement the methods like scheduleXXX(..) that are not part of ThreadPoolExecutor? – Chriss Mar 27 '14 at 10:47
  • @Chriss: What I meant is, do use a scheduled executor, but let it simply post (submit the task) to a thread pool executor with priority queue. This way, you can do everything you can do with a scheduled executor and still have prioritized execution in effect – Enno Shioji Mar 27 '14 at 11:12
  • Downside is (potentially) a tiny loss in performance/scheduling accuracy but I'm most certain it'd be too small matter – Enno Shioji Mar 27 '14 at 12:15