BackingMaps can act as FIFO (first-in, first-out) queues thanks to the getNextKey(int timeout)
method. This method retrieves the next key in the map determined by its insertion order. When this method is called, a lock on the object is obtained so that next call to getNextKey(int timeout)
does not return the same object. In order to iterate over an entire BackingMap, the application must explicitly remove the object with that key when the thread or process is finished with it. Otherwise, the key remains at the front of the queue and the next call to getNextKey(int timeout)
returns a key that we have already operated upon. Without removing the key, a call to getNextKey(int timeout)
will return the same key whenever the lock on that object is released. The getNextKey(int timeout)
method takes a number of milliseconds to wait for an object to become available in the BackingMap. If this timeout is exceeded, then the method gives up and returns null.
We can use the getNextKey(int...