| | |
| | | private final List<AbstractNodeTask> waitingQueue = new ArrayList<>(); |
| | | private final Map<BasicNode, AbstractNodeTask> workingList = new HashMap<>(); |
| | | private final ThreadGroup threadGroup; |
| | | private final List<Thread> threads = new ArrayList<>(); |
| | | |
| | | |
| | | /** |
| | |
| | | for (int i = 0; i < threadCount; i++) { |
| | | Thread t = new Thread(threadGroup, this, name + "[" + i + "]"); |
| | | t.setPriority(Thread.MIN_PRIORITY); |
| | | threads.add(t); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Starts the threads consuming this queue. |
| | | * <p> |
| | | * The threads are not started by the constructor so that {@code this} is not published to them |
| | | * before construction has completed. |
| | | * |
| | | * @return this queue |
| | | */ |
| | | public NodeSearcherQueue start() { |
| | | for (Thread t : threads) { |
| | | t.start(); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | |
| | | throw new IllegalArgumentException("null argument"); |
| | | } |
| | | waitingQueue.add(nodeTask); |
| | | notify(); |
| | | notifyAll(); |
| | | // System.out.println("Queued " + nodeTask + " in " + _name); |
| | | } |
| | | |
| | |
| | | if (task != null) { |
| | | task.cancel(); |
| | | } |
| | | notify(); |
| | | notifyAll(); |
| | | } |
| | | |
| | | /** |
| | |
| | | throw new IllegalArgumentException("null argument"); |
| | | } |
| | | workingList.remove(task.getNode()); |
| | | notify(); |
| | | notifyAll(); |
| | | // System.out.println("Flushed " + task + " from " + _name); |
| | | } |
| | | |