I found out serependititly that the LabelRegions class, which allows iterating through the labels of a Labeling cannot be used concurrently.
When trying the access a region with a specific label, the cache is update if needed. In multithreaded applications, the cache updated might get called concurrently and this is probably the reason for the error.
Maybe it could be specified in the javadocs?
Maybe it can be fixed by declaring the update() method synchronized?
The error stack when trying to access regions concurrently looks like the following:
Exception in thread "[NucleiSplitter] thread 0" java.lang.IndexOutOfBoundsException: Index: 459, Size: 459 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.get(ArrayList.java:322) at net.imglib2.roi.labeling.LabelRegions.update(LabelRegions.java:361) at net.imglib2.roi.labeling.LabelRegions.getLabelRegion(LabelRegions.java:116) at fiji.plugin.cwnt.segmentation.NucleiSplitter$1.run(NucleiSplitter.java:124)
I found out serependititly that the LabelRegions class, which allows iterating through the labels of a Labeling cannot be used concurrently.
When trying the access a region with a specific label, the cache is update if needed. In multithreaded applications, the cache updated might get called concurrently and this is probably the reason for the error.
update()
methodsynchronized
?The failing method is the private method
update
https://github.com/imglib/imglib2-roi/blob/master/src/main/java/net/imglib2/roi/labeling/LabelRegions.java#L329The error stack when trying to access regions concurrently looks like the following:
Exception in thread "[NucleiSplitter] thread 0" java.lang.IndexOutOfBoundsException: Index: 459, Size: 459 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.get(ArrayList.java:322) at net.imglib2.roi.labeling.LabelRegions.update(LabelRegions.java:361) at net.imglib2.roi.labeling.LabelRegions.getLabelRegion(LabelRegions.java:116) at fiji.plugin.cwnt.segmentation.NucleiSplitter$1.run(NucleiSplitter.java:124)