I have created a custom .hpi Jenkins plugin to prioritize (move to the front of the queue) some jobs that arrive in the queue. The logic is very simple and can be found in CustomSorter.java
In the plugin I am basically just overriding the default sortBuildableItems() method in QueueSorter class and load it at Jenkins initialization.
After uploading the plugin everything works as expected (builds that meet specific criteria are pushed to the front of the queue) for usually 10-12 hours but then the build queue gets stuck and no jobs are executed even though all executors are free / available.
Later edit:
In the Attachments Section you can find the main classes used, the .hpi packaged form and a full log file with a thread dump generated at the end of the logs file.