Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
新しいタスクをキューの一番上に追加するか一番下に追加するかを選択できる Executor が必要です。それを達成する最も簡単な方法は何ですか?
PriorityQeueueこの機能は、を使用することで(またはPriorityBlockingQueueニーズに応じて)実現できると思います。
PriorityQeueue
PriorityBlockingQueue
これらのキューは、コンパレータに依存する順序でタスクを処理します。このコンパレータは作成時にキューに渡されますが、特定のタスクの優先度が低いか高いかを判断できる独自のロジックを持つカスタムコンパレータを実装できます。