【问题标题】:Batik: IllegalStateException when I call invokeLater from a threadBatik:当我从线程调用 invokeLater 时出现 IllegalStateException
【发布时间】:2013-01-27 15:01:37
【问题描述】:

我已经在这里发布了一个类似的问题:Batik IllegalStateException when resizing the JComponent containing the JSVGCanvas。但是,我可以将问题简化为最少的代码集。也许这有助于某人找到我的问题。

我从一个线程重复调用以下代码:

//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();
    }
}

有时我会收到以下异常:

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)

这是 Batik 中的错误还是我做错了什么?

【问题讨论】:

    标签: java multithreading illegalstateexception batik


    【解决方案1】:

    我有类似的问题。相同的 IllegalStateException 仅在特殊用例中发生。

    我的问题是我的代码在

    documentLoadingCompleted(SVGDocumentLoaderEvent P_event)
    

    因为我正在执行我的代码

    gvtRenderingCompleted(GVTTreeRendererEvent P_e)
    

    一切正常。

    【讨论】:

    • 您好,感谢您的回答。它现在可以使用类似的解决方案。正如您所说,诀窍是在 gvtRenderingCompleted 期间运行代码。当您调用 setDocument() 时,我没有意识到 JSVGCanvas 会获得一个新的 UpdateManager。但现在一切正常。
    【解决方案2】:

    http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/util/RunnableQueue.html#invokeLater%28java.lang.Runnable%29

      public void invokeLater(Runnable r)
    
      Schedules the given Runnable object for a later invocation, and returns. An exception is thrown if the RunnableQueue was not started. 
      Throws:
        IllegalStateException - if getThread() is null.
    

    您的 RunnableQueue 似乎尚未启动...

    【讨论】:

    • 感谢您的回答。是的,我已经看到,当线程引用设置为 null 时会引发异常,这发生在 Batik 的 RunnableQueue 的 run() 方法的末尾。大多数情况下这有效,但有时队列似乎还没有开始。有没有同步的方法?
    猜你喜欢
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-11
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多