Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // want to parallelize this for loop
- for (Task task : tasks) {
- if (task.getCategories().isEmpty() || task.getEventList() == null
- || task.getMetaInfo() == null) {
- continue;
- }
- String itemId = task.getEventList().getId();
- String categoryId = task.getCategories().get(0).getId();
- Processor fp = new Processor(siteId, itemId, categoryId, poolType);
- Map<String, Integer> holder = fp.getDataHolder();
- if (!holder.isEmpty()) {
- for (Map.Entry<String, Integer> entry : holder.entrySet()) {
- info.putIfAbsent(entry.getKey(), entry.getValue());
- }
- List<Integer> values = new ArrayList<>();
- for (String key : holder.keySet()) {
- values.add(info.get(key));
- }
- itemToNumberMapping.put(itemId, StringUtils.join(values, ","));
- catToValueHolder.put(categoryId, StringUtils.join(values, ","));
- }
- Category cat = getCategory(task, holder.isEmpty());
- dealsByLeafCategory.add(cat);
- LinkedList<String> ids = getCategoryIds(task);
- catHolder.put(categoryId, ids.getLast());
- itemIds.add(itemId);
- }
- private final ExecutorService service = Executors.newFixedThreadPool(10);
- List<Future<Output>> futures = new ArrayList<Future<Output>>();
- for (final Input input : inputs) {
- Callable<Output> callable = new Callable<Output>() {
- public Output call() throws Exception {
- Output output = new Output();
- // process your input here and compute the output
- return output;
- }
- };
- futures.add(service.submit(callable));
- }
- service.shutdown();
- List<Output> outputs = new ArrayList<Output>();
- for (Future<Output> future : futures) {
- outputs.add(future.get());
- }
Add Comment
Please, Sign In to add comment