ForkJoinTasks seem to make java ImageIO.read crash with IOExceptions.

View: New views
2 Messages — Rating Filter:   Alert me  

ForkJoinTasks seem to make java ImageIO.read crash with IOExceptions.

by Qin, Henry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ForkJoinTasks seem to make java ImageIO.read crash with IOExceptions.

Hi,


I have the following code:

public class ParallelPusher{

    static Queue<byte[]> theQueue;

    public void compute(){

        while (!theQueue.isEmpty()){

            byte[] bytes = theQueue.poll();

            if (bytes == null) return; //just a safety check

            ByteArrayInputStream bais = null;

            try{

                bais = new ByteArrayInputStream(bytes);

                SimpleHistogram sht = new SimpleHistogram();

                sht.compute(bais);

                ShannonEntropy se = new ShannonEntropy();

                BufferedImage img = se.compute(sht);

            }

            catch(IOException ioe){

                System.err.println("An IOException has occured.");

                ioe.printStackTrace();

            }


        }

    }

}

Inside the SimpleHistogram.compute:

 

public void compute(File file) throws IOException {

    BufferedImage bufImage = ImageIO.read(file);

    loadBufferedImage(bufImage);

  }

When I call the compute method directly, from a new instance in main:

(new ParallelPusher()).compute();

It works fine with no errors.

However, when I execute it from a ForkJoinPool, with Parallism set to 1, and running only one task, ImageIO crashes:

    ForkJoinPool pool = new ForkJoinPool(1);

   pool.execute(new ParallelPusher());

ImageIO crashes with the following stacktrace:

java.io.IOException: closed

        at javax.imageio.stream.ImageInputStreamImpl.checkClosed(ImageInputStreamImpl.java:96)

        at javax.imageio.stream.ImageInputStreamImpl.close(ImageInputStreamImpl.java:843)

        at javax.imageio.stream.FileCacheImageInputStream.close(FileCacheImageInputStream.java:230)

        at javax.imageio.ImageIO.read(ImageIO.java:1425)

        at javax.imageio.ImageIO.read(ImageIO.java:1326)

        at gov.pnnl.dici.image.SimpleHistogram.compute(SimpleHistogram.java:62)

        at gov.pnnl.dici.image.ParallelPusher.compute(ParallelPusher.java:24)

        at jsr166y.RecursiveAction.exec(RecursiveAction.java:147)

        at jsr166y.ForkJoinTask.quietlyExec(ForkJoinTask.java:459)

        at jsr166y.ForkJoinWorkerThread.mainLoop(ForkJoinWorkerThread.java:356)

        at jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:341)

I believe the error has to do with the fact that ForkJoin doesnt play well with blocking IO, but that is inconsistent with an earlier result I got, where I had ForkJoin threads writing a lot of files to disk. I am curious about why the exact same code should crash ImageIO under ForkJoin, but not normally, and whether there is a fix for this.

Thanks,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Parent Message unknown Re: ForkJoinTasks seem to make java ImageIO.read crash with IOExceptions.

by Qin, Henry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

RE: ForkJoinTasks seem to make java ImageIO.read crash with IOExceptions.

Please ignore the previous message. Apparently, the problem was that I had an isQuiescentCheck() running before the pool became active, and after I called pool.execute(ParallelPusher).

Apologies,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest