Search code examples
javamultithreadingpriority-queue

change existing task prority in PriorityBlockingQueue


how can I change a certain task priority if it's already on the blocking queue (assuming the poll is full) and I now want it to be on an higher priority?

E.G: implementing this answer

Specify task order execution in Java

I put thread poll of 3, send 8 tasks all with priority of 1.

Now 3 are executing and 5 are waiting for an available thread.

Now I want task number 3 on the waiting list to be priority 2, means it will execute right away when a thread is open before the other 4.

Can it be done?

P.S - I want to do it on an android app, is it recommended?


Solution

  • If it's in the PriorityQueue already, changing the priority won't affect anything. You'd have to remove and re-insert it.