I was working on a project and ran into some issues which i dont know what would be best. What I want to do is have 4 queue running each queue has a priority to it so each one runs for its predetermined amount of time in a round robin format and was thinking of using the Priority Queue for each queue then I found in the Java api that a linked list is also a queue (if im reading that right) which is a FIFO queue.
The main goal of the project is to take a “process” and then assign it a priority and let this process run in one of the queue then re-assets its priority and either change the queue its in or leave it where it is.
Which would be a better approach the linked list or the priority queue?
Thanks for any input on this
I was working on a project and ran into some issues which i dont
Share
You can always implement the Java Collection Library’s LinkedList and tweak some methods to turn it into a priority queue. Bam–best of both worlds.
A way to modify it to fit your project would be to overload the
add()method to include a priority parameter. Although a queue is traditionally FIFO, the LinkedList has aremoveFirst()and aremoveLast()function (even a “remove at”–remove(int index)). So, you have all the tools you need with the library class. I assume this is for a school project, so it’s a nice way to show off an understanding of OOP inheritance also.Another method is to just have a ‘LinkedList’ of a “Process” class that you’ll define with an
int priorityproperty. That way, you can have some sort of process manager that will manipulate the LinkedList of Process objects by peering through each object’spriorityproperty.