Search in sources :

Example 1 with GetAttributes

use of com.spaceprogram.simplejpa.operations.GetAttributes in project simplejpa by appoxy.

the class ConcurrentRetriever method getParallel.

private static List<ItemAndAttributes> getParallel(List<SdbItem> items, Executor executor, EntityManagerSimpleJPA em) throws InterruptedException, ExecutionException {
    CompletionService<ItemAndAttributes> ecs = new ExecutorCompletionService<ItemAndAttributes>(executor);
    for (SdbItem item : items) {
        Callable callable = new GetAttributes(item, em);
        ecs.submit(callable);
    }
    List<ItemAndAttributes> ret = new ArrayList<ItemAndAttributes>();
    int n = items.size();
    for (int i = 0; i < n; ++i) {
        ItemAndAttributes r = ecs.take().get();
        if (r != null) {
            ret.add(r);
        }
    }
    return ret;
}
Also used : GetAttributes(com.spaceprogram.simplejpa.operations.GetAttributes) SdbItem(com.spaceprogram.simplejpa.SdbItem) ArrayList(java.util.ArrayList) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ItemAndAttributes(com.spaceprogram.simplejpa.ItemAndAttributes) Callable(java.util.concurrent.Callable)

Aggregations

ItemAndAttributes (com.spaceprogram.simplejpa.ItemAndAttributes)1 SdbItem (com.spaceprogram.simplejpa.SdbItem)1 GetAttributes (com.spaceprogram.simplejpa.operations.GetAttributes)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1