Skip to content

Commit 3c2e393

Browse files
committed
Update ForkJoinPool
1 parent 50f9589 commit 3c2e393

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

modules/core/src/main/java/jsymbolic2/processing/MIDIFeatureProcessor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
public class MIDIFeatureProcessor {
4747
/* FIELDS ****************************************************************/
4848

49-
private static Map<String, MIDIFeatureExtractor> name2feature = new HashMap<>();
49+
private static Map<String, MIDIFeatureExtractor> name2feature = new ConcurrentHashMap<>();
5050

5151
/**
5252
* The window size in seconds used for dividing up the recordings to
@@ -345,7 +345,7 @@ public void onCompletion(CountedCompleter<?> caller) {
345345
double[][][] dependencies = new double[sequences.size()][ArrayUtils.nullToEmpty(featureExtractor.getDepenedencies()).length][];
346346
for (int j = 0; j < ArrayUtils.nullToEmpty(featureExtractor.getDepenedencies()).length; j++) {
347347
String dependency = featureExtractor.getDepenedencies()[j];
348-
dependencies[i][j] = map.get(name2feature.get(dependency))[i];
348+
dependencies[i][j] = map.get(dependency)[i];
349349
}
350350
try {
351351
results[i] = featureExtractor.extractFeature(sequences.get(i),
@@ -399,17 +399,20 @@ public double[][][] getFeatures(Sequence[] windows, MeiSpecificStorage meiSpecif
399399
}
400400
ForkJoinPool pool = ForkJoinPool.commonPool();
401401
ConcurrentHashMap<String, double[][]> resultsMap = new ConcurrentHashMap<>();
402-
IntStream.range(0, featureExtractorsDefinitions.length)
402+
List<ForkJoinTask<Void>> forkJoinTasks = IntStream.range(0,
403+
featureExtractorsDefinitions.length)
403404
.filter(i -> featuresToSaveMask[i])
404405
.mapToObj(i -> name2feature.get(featureExtractorsDefinitions[i].name))
405406
.map(featureDefinition -> pool.submit(new Worker(null,
406407
Arrays.stream(windows).toList(),
407408
representations,
408409
resultsMap,
409-
featureDefinition))).toList().forEach(voidForkJoinTask -> {
410+
featureDefinition))).toList();
411+
forkJoinTasks.forEach(voidForkJoinTask -> {
410412
try {
411413
voidForkJoinTask.get();
412414
} catch (InterruptedException | ExecutionException e) {
415+
e.printStackTrace();
413416
throw new RuntimeException(e);
414417
}
415418
});

0 commit comments

Comments
 (0)