@Override public long[][] compute() throws Exception { long[][] result = new long[geneList1.size()][]; final OperationPool op = OperationPool.getInstance(); final Collection<Callable<long[]>> threadList = new ArrayList<Callable<long[]>>(); for (int i = 0; i < geneList1.size(); i++) { final int chromoindex = i; Callable<long[]> currentThread = new Callable<long[]>() { @Override public long[] call() throws Exception { long[] chromoresult = new long[geneList1.get(chromoindex).size()]; if ((geneList1 != null) && (geneList2 != null)) { chromoresult = handleCases(geneList1.get(chromoindex), geneList2, chromoindex); } // tell the operation pool that a chromosome is done op.notifyDone(); return chromoresult; } }; threadList.add(currentThread); } if (op.startPool(threadList) == null) { return null; } int i = 0; for (long[] currentResult : op.startPool(threadList)) { if (currentResult != null) { result[i++] = currentResult; } } return result; }
@Override public GeneList compute() throws Exception { final OperationPool op = OperationPool.getInstance(); final Collection<Callable<ListView<Gene>>> threadList = new ArrayList<Callable<ListView<Gene>>>(); for (int i = 0; i < geneList.size(); i++) { final ListView<Gene> currentGeneList = geneList.get(i); Callable<ListView<Gene>> currentThread = new Callable<ListView<Gene>>() { @Override public ListView<Gene> call() throws Exception { if (currentGeneList == null) { return null; } ListViewBuilder<Gene> resultLVBuilder = new GeneListViewBuilder(); for (int j = 0; (j < currentGeneList.size()) && !stopped; j++) { Gene currentGene = currentGeneList.get(j); Gene geneToAdd = createGeneCopyWithConstantScore(currentGene); resultLVBuilder.addElementToBuild(geneToAdd); } // tell the operation pool that a chromosome is done op.notifyDone(); return resultLVBuilder.getListView(); } }; threadList.add(currentThread); } List<ListView<Gene>> result = op.startPool(threadList); if (result == null) { return null; } else { return new SimpleGeneList(result, geneList.getGeneScoreType(), geneList.getGeneDBURL()); } }