开发者

How to multithread collection iteration operating on a predicate?

开发者 https://www.devze.com 2022-12-24 01:52 出处:网络
For sake of abstraction, let\'s assume t开发者_Python百科hat I have a Map<Double, Collection<Employee>>

For sake of abstraction, let's assume t开发者_Python百科hat I have a

Map<Double, Collection<Employee>>

where key is salary threshold. Or for people familiar with Google collections it would be as Multimap

I want to do a database lookup for each Employee's salary and if it's less than the salary threshold remove the employee it from the collection. How can I do this in multi-threaded manner, preferably using a fixed threadpool executor?

Again, for google collections savvy folks, if done via Predicate that does a DB lookup and filter the collection, I would greatly appreciate.


Concurrent filtering on an inplace datastructure is asking too much in my feeling. You need at least a way to mark Employees which are currently being processed.

Rather use an input and output map. Let the threads work through the input map (for which I would use BlockingQueues as the Collection) and write to the output map all employees which fit your test.

0

精彩评论

暂无评论...
验证码 换一张
取 消