I have a collection of BufferedImage
instances, one main image and some subimages created by calling getSubImage
on the main image. The subimages do not overlap. I am also making modifications to the subimage and I want to split this into multiple threads, one per subimage.
From my understanding of how BufferedImage
, Raster
and DataBuffer
work, this should be safe because:
- Each instance of
BufferedImage
(and its respectiveWritableRaster
andSampleModel
) is accessed from only one thread. - The shared
ColorModel
is immutable - The
DataBuffer
has no fields that can be modified (the only thing that can change is elements of the backing array.) - Modifying disjoint segments of an array in separate threads is safe.
However I cannot find anything in the documentation that says that it is definitely safe to do this. Can I assume it is safe? I know that it is possible to work on copies of the child Raster
s but I would prefer to avoid this because of memory constraints.
Otherwise, is it possible to make the operation thread-safe without copying regions of the parent image?