java.util.concurrent.BlockingQueue
が便利contains
方法があります。java.util.concurrent.BlockingQueueの述語(/ find/search)が含まれていますか?
/**
* Returns {@code true} if this queue contains the specified element.
* More formally, returns {@code true} if and only if this queue contains
* at least one element {@code e} such that {@code o.equals(e)}.
*
* @param o object to be checked for containment in this queue
* @return {@code true} if this queue contains the specified element
* @throws ClassCastException if the class of the specified element
* is incompatible with this queue
* (<a href="../Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if the specified element is null
* (<a href="../Collection.html#optional-restrictions">optional</a>)
*/
public boolean contains(Object o);
を私の必要性は、もう少し具体的です:predicate
/検索条件を適用します。この短くする方法はありますか
Using a ArrayBlockQueue
Invoking toArray
これは動作しますが、キューが大きい場合はどうなりますか?これはメモリ割り当ての問題を引き起こす可能性があります。
代わりにいくつかの奇妙な、非queue-にキューを押し込もしようとする複数のキューのために良い場合のように思えます嫌な行動。 – pvg
@pvg検索は、メッセージ内の特定のIDを見つけることに基づいています。固定述部に基づいて「複数の」キューを持つケースはありません。そのアプローチに従えば、すべてのメッセージのキューが必要です。 – javadba
メッセージIDが一意である場合は、.equalsを上書きするだけです。または何らかの優先順位を設定します。特定のメッセージを特定する必要がある場合、注文を課すキューを使用するポイントは何ですか?キューをnot-a-queueのように振る舞うにはどうすればいいのか、解決しようとしている問題を説明する必要があります。 – pvg