Safe to update separate regions of a BufferedImage in separate threads?
Posted
by finnw
on Stack Overflow
See other posts from Stack Overflow
or by finnw
Published on 2010-05-18T12:47:31Z
Indexed on
2010/05/18
12:51 UTC
Read the original article
Hit count: 481
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) is accessed from only one thread. - The shared
ColorModelis immutable - The
DataBufferhas 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 Rasters 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?
© Stack Overflow or respective owner