Search code examples
javamultithreadingillegalstateexceptionbatik

Batik: IllegalStateException when I call invokeLater from a thread


I already posted a similar question here: Batik IllegalStateException when resizing the JComponent containing the JSVGCanvas. I could however reduce the problem to a minimal set of code. Maybe that helps someone to find my problem.

I am calling the following code from a Thread repeatedly:

//currentComponent is a custom JComponent that contains the JSVGCanvas
if(currentComponent != null && currentComponent.getSvgCanvas().getUpdateManager() != null)
{
    try
    {
        currentComponent.getSvgCanvas().getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable()
        {
            @Override
            public void run()
            {
                resetDocument();
            }

            private void resetDocument()
            {
                currentComponent.getSvgCanvas().setDocument(currentComponent.getSvgCanvas().getSVGDocument());
            }
        });
    }
    catch(Exception e)
    {
        System.out.println("Error");
        e.printStackTrace();
    }
}

Sometimes I get the following Exception:

java.lang.IllegalStateException: RunnableQueue not started or has exited
    at org.apache.batik.util.RunnableQueue.invokeLater(RunnableQueue.java:277)
    at java.lang.Thread.run(Unknown Source)

Is this a bug in Batik or am I doing something wrong?


Solution

  • I had simmilar problem.Same IllegalStateException occured only in special usecases.

    My problem was that my code was executed during

    documentLoadingCompleted(SVGDocumentLoaderEvent P_event)
    

    since I'm executing my code during

    gvtRenderingCompleted(GVTTreeRendererEvent P_e)
    

    everything works.