2014-01-06 11 views
15

私はBlockingQueueと非常に似ている1つのBlockingMapデータ構造を持っていたいと思います。 BlockingQueueのtakeメソッドは、elementが利用可能になるまでそこで待機します。対応するキーが利用可能になるまでBlockingMapのgetメソッドを待機させたいですか?このような種類のデータ構造が利用できるのですか?BlockingMapはBlockingQueueとしてJavaにありますか?

+1

あなたは常に同様の結果を達成するためにBlockingQueueの、未来または交換器とのConcurrentHashMap組み合わせることができます。 – Mikhail

+0

@zjffdu興味深い 'BlockingMap' http://cs.oswego.edu/pipermail/concurrency-interest/2007-June/004211.html –

答えて

10

私は単純にBlockingQueue<Map.Entry<K,V>>を使用しました。しかし、最近、私はこれを見つけたBlocking Map for Java。しかし、それを自分で使ったことはありません。

4

私が希望するのはthisです。

public class BlockingHashMap<K,V> 
extends java.lang.Object 
implements BlockingMap<K,V> 

public V get(java.lang.Object key) 

を取得し、このマップがキーのマッピングを保持していない場合は指定されたキーがマッピングされた、またはnullされている値を返します。 nullがで指定された要求されたキー

がないことを示すために、特殊なマーカーとして使用されていることを 注:

get in interface BlockingMap<K,V> 

パラメータ:

key - the key whose associated value is to be returned 

get in interface java.util.Map<K,V> 

で指定します

の戻り値:

the value to which the specified key is mapped, or null if this map contains no mapping for the key 

例外:

java.lang.ClassCastException - if the key is of an inappropriate type for this map 
java.lang.NullPointerException - if the specified key is null and this map does not permit null keys (optional) 
java.lang.IllegalStateException - if the map has been shut-down 
+0

' java.lang.Object'を拡張しますか? Javaではすべてのオブジェクトインスタンスがすでにそれを拡張しています – rkosegi

+0

javadocがそれを行う方法です。 –

関連する問題