You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by kototama kototama <ko...@gmail.com> on 2011/03/30 12:35:40 UTC

Deadlock with gvtRenderingCompleted without Swing threads

Hello,

I would like to block and wait until the rendering of the SVG DOM is
completed. What is wrong with the following code? It blocks even if no
Swing thread is involved.

Thanks in advance for your help.

public class DeadLock {

	private static final String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final Object mutext = new Object();

		DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
		Document doc = impl.createDocument(svgNS, "svg", null);

		JSVGCanvas canvas = new JSVGCanvas();
		canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
			@Override
			public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
				System.out.println("completed");
				synchronized (mutext) {
					mutext.notifyAll();
				}

			}
		});

		synchronized (mutext) {
			System.out.println("Loading document");
			canvas.setDocument(doc);
			System.out.println("Waiting for document to be loaded...");
			try {
				mutext.wait();
				System.out.println("rendering finished");
			} catch (InterruptedException ie) {
				ie.printStackTrace();
			}
		}
	}

}

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Deadlock with gvtRenderingCompleted without Swing threads

Posted by jonathan wood <jo...@gmail.com>.
The lower synchronized block will likely execute before
gvtRenderingComplete() is called.  The lower block will be holding the mutex
when the upper synchonized access is attempted....deadlock

On Wed, Mar 30, 2011 at 6:35 AM, kototama kototama <ko...@gmail.com>wrote:

> Hello,
>
> I would like to block and wait until the rendering of the SVG DOM is
> completed. What is wrong with the following code? It blocks even if no
> Swing thread is involved.
>
> Thanks in advance for your help.
>
> public class DeadLock {
>
>        private static final String svgNS =
> SVGDOMImplementation.SVG_NAMESPACE_URI;
>
>        /**
>         * @param args
>         */
>        public static void main(String[] args) {
>                final Object mutext = new Object();
>
>                DOMImplementation impl =
> SVGDOMImplementation.getDOMImplementation();
>                Document doc = impl.createDocument(svgNS, "svg", null);
>
>                JSVGCanvas canvas = new JSVGCanvas();
>                canvas.addGVTTreeRendererListener(new
> GVTTreeRendererAdapter() {
>                        @Override
>                        public void
> gvtRenderingCompleted(GVTTreeRendererEvent e) {
>                                System.out.println("completed");
>                                synchronized (mutext) {
>                                        mutext.notifyAll();
>                                }
>
>                        }
>                });
>
>                synchronized (mutext) {
>                        System.out.println("Loading document");
>                        canvas.setDocument(doc);
>                        System.out.println("Waiting for document to be
> loaded...");
>                        try {
>                                mutext.wait();
>                                System.out.println("rendering finished");
>                        } catch (InterruptedException ie) {
>                                ie.printStackTrace();
>                        }
>                }
>        }
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>