[JAI-IMAGEIO] JAI and multiple threads
I'm using JAI in a multi-threading context and I've got some
questions. I've a batch-processing class which performs the same
operation on a set of images. For clarity, let's say I've got 100
images that are processed sequentially in 130 seconds. Now I've
changed my code so two images are processed at the same time (I'm
running the code on a MacBook Pro with a dual-core, this is a way to
exploit the second processor). I see that the parallelized code
completes in 75 seconds. Now, the algorithm is perfectly
parallelizable, as it mostly works on different images; there are
just a pair of common images which are used read-only by both
threads. In other words, I've got images A, B and X(i), 0 < i < 100.
Thread #1 accesses A, B and X(m); Thread #2 accesses A, B and X(n),
with m != n.
On these premises, I'd expect something closer to 130/2 = 65 seconds,
as there should be just a few seconds overhead above the optimal
time. What I'm missing? Can those 10 more seconds be due to the
access to common images (maybe there's some synchronized block in JAI
access?). In this case, would I benefit from duplicating the common
images so each thread works on a completely separate set of objects?
For the record, I'm running in Java pure mode, as on Mac OS X 10.4
there's not native library support (yet).
Thanks in advance.
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
http://www.tidalwave.it/blog - Fabrizio.Giudici@tidalwave.it
mobile: +39 348.150.6941 - fax: +39 027.005.105.36