views:

45

answers:

1

For sake of abstraction, let's assume that 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.

A: 

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.

Christopher Oezbek