I am trying to achieve following:
Map<Integer, Object>
(let's say from now Map1
and Map2
Object
is always inserted to Map1
first Integer
value is incremented with AtomicInteger
every time Object
is inserted to Map1
Object
from the Map1
and move it to Map2
and then perform asynchronous operation with the Object
Object
from Map2
and repeat Map1
is sort of a queue and Map2
contains all running operations. The amount of running operations can be adjusted to be more than 1 at a time.
For example I execute 5 operations in a row and max amount for running operations is 4, the sequence would be:
Put all 5 into Map1
with 0,1,2,3,4 ids. Then indexes 0,1,2,3 should be removed and moved to Map2
. When first Object
from Map2
is ready, it should be removed and the last from Map1
moved to Map2
.
I tried with ConcurrentHashMap
but iterating it with Iterator.next()
started from the last inserted item and had some problems removing item from Map2
when the object got ready.
Map1 is sort of a queue
使用阻塞队列,这是一种FIFO数据结构。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.