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 Sudhakar S <ye...@hotmail.com> on 2006/08/18 06:16:17 UTC

Problem in invokeAndWait

Hi Thomas,

I am displaying more number of shapes in SVGDocument. To update this shapes
attributes dynamically, i did the changes within Update Manager’s
"invokeLater". Using "invokeLater", it is working fine without any problem.
But it is happening in separate thread, I couldn't synchronize with main
thread. So changed "invokeLater" to "invokeAndWait". But after changed to
"invokeAndWait", it is not at all drawing the shapes. It simply hangs. So I
couldn’t find any solution to resolve this.

While go through the nabble threads related to “invokeAndWait”, it told
"updatecompleted" must be completed before calling “invokeAndWait”. So can
you please tell how to find whether updatecompleted is completed or not? 

I have attached thread dump along with this mail. Please let me know the
problem. I would be very helpful for me to proceed further.

Full thread dump Java HotSpot(TM) Client VM (1.5.0_02-b09 mixed mode,
sharing):

"Thread-9" prio=2 tid=0x00aab1f8 nid=0x9dc in Object.wait()
[0x03b6f000..0x03b6fa68]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1d6a01a0> (a java.awt.EventQueue$1AWTInvocationLock)
        at java.lang.Object.wait(Unknown Source)
        at java.awt.EventQueue.invokeAndWait(Unknown Source)
        - locked <0x1d6a01a0> (a java.awt.EventQueue$1AWTInvocationLock)
        at
org.apache.batik.util.EventDispatcher.fireEvent(EventDispatcher.java:49)
        at
org.apache.batik.swing.gvt.GVTTreeRenderer.fireEvent(GVTTreeRenderer.java:148)
        at
org.apache.batik.swing.gvt.GVTTreeRenderer.run(GVTTreeRenderer.java:130)

"Timer-0" daemon prio=7 tid=0x00aa6d10 nid=0x604 in Object.wait()
[0x03b1f000..0x03b1fbe8]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1d5d64e0> (a java.util.TaskQueue)
        at java.lang.Object.wait(Unknown Source)
        at java.util.TimerThread.mainLoop(Unknown Source)
        - locked <0x1d5d64e0> (a java.util.TaskQueue)
        at java.util.TimerThread.run(Unknown Source)

"RunnableQueue-0" daemon prio=7 tid=0x02cbcd30 nid=0xb78 in Object.wait()
[0x036ef000..0x036efc68]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1d7dc310> (a java.awt.EventQueue$1AWTInvocationLock)
        at java.lang.Object.wait(Unknown Source)
        at java.awt.EventQueue.invokeAndWait(Unknown Source)
        - locked <0x1d7dc310> (a java.awt.EventQueue$1AWTInvocationLock)
        at 

org.apache.batik.swing.svg.AbstractJSVGComponent$BridgeUserAgentWrapper.invokeAndWait(AbstractJSVGComponent.java:2953)
        at 

org.apache.batik.swing.svg.AbstractJSVGComponent$BridgeUserAgentWrapper.checkLoadExternalResource(AbstractJSVGComponent.java:

2908)
        at
org.apache.batik.bridge.SVGImageElementBridge.createImageGraphicsNode(SVGImageElementBridge.java:189)
        at
org.apache.batik.bridge.SVGImageElementBridge.buildImageGraphicsNode(SVGImageElementBridge.java:166)
        at
org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(SVGImageElementBridge.java:112)
        at
org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:199)
        at
org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:161)
        at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:131)
        at
org.apache.batik.bridge.SVGGElementBridge.handleElementAdded(SVGGElementBridge.java:118)
        at
org.apache.batik.bridge.SVGGElementBridge.handleDOMNodeInsertedEvent(SVGGElementBridge.java:104)
        at
org.apache.batik.bridge.BridgeContext$DOMNodeInsertedEventListener.handleEvent(BridgeContext.java:1513)
        at
org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:350)
        at
org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:407)
        at
org.apache.batik.dom.events.EventSupport.dispatchEvent(EventSupport.java:281)
        at
org.apache.batik.dom.AbstractNode.dispatchEvent(AbstractNode.java:1010)
        at
org.apache.batik.dom.AbstractParentNode.fireDOMNodeInsertedEvent(AbstractParentNode.java:424)
        at
org.apache.batik.dom.AbstractParentNode.appendChild(AbstractParentNode.java:224)
        at NodeRenderer.drawLabel(NodeRenderer.java:194)
        at NodeRenderer.draw(NodeRenderer.java:67)
        at GraphView.render(GraphView.java:957)
        - locked <0x1e050c70> (a GraphView)
        at GraphView$2.run(GraphView.java:865)
        at org.apache.batik.util.RunnableQueue.run(RunnableQueue.java:203)
        at java.lang.Thread.run(Unknown Source)

"Callback" prio=7 tid=0x02cbc2f0 nid=0x224 in Object.wait()
[0x03adf000..0x03adfd68]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1ddb00f0> (a java.util.Vector)
        at java.lang.Object.wait(Unknown Source)
        at Callback.run(Callback.java:40)
        - locked <0x1ddb00f0> (a java.util.Vector)

"DestroyJavaVM" prio=5 tid=0x000377f8 nid=0xab0 waiting on condition
[0x00000000..0x0007fae8]

"Timeout" prio=7 tid=0x02ff38a0 nid=0xaa4 waiting on condition
[0x036af000..0x036af9e8]
        at java.lang.Thread.sleep(Native Method)
        at Timeout.run(Timeout.java:53)

"Session 0" prio=7 tid=0x02d653f8 nid=0x400 runnable
[0x0362f000..0x0362fa68]
        at java.net.PlainDatagramSocketImpl.peekData(Native Method)
        - locked <0x1ddb0300> (a java.net.PlainDatagramSocketImpl)
        at java.net.DatagramSocket.receive(Unknown Source)
        - locked <0x1ddb0360> (a java.net.DatagramPacket)
        - locked <0x1ddb0380> (a java.net.DatagramSocket)
        at Session.receiver(Session.java:738)
        at Session.run(Session.java:299)

"Thread-3" prio=5 tid=0x030567f0 nid=0x904 in Object.wait()
[0x037ef000..0x037efae8]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1e175190> (a java.lang.String)
        at java.lang.Object.wait(Unknown Source)
        at GraphManager$StatusHandler.run(GraphManager.java:4988)
        - locked <0x1e175190> (a java.lang.String)

"AWT-EventQueue-0" prio=7 tid=0x02cfec30 nid=0xc78 in Object.wait()
[0x0376f000..0x0376fb68]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1d6b1618> (a
org.apache.batik.util.RunnableQueue$LockableLink)
        at java.lang.Object.wait(Unknown Source)
        at
org.apache.batik.util.RunnableQueue$LockableLink.lock(RunnableQueue.java:607)
        - locked <0x1d6b1618> (a
org.apache.batik.util.RunnableQueue$LockableLink)
        at
org.apache.batik.util.RunnableQueue.invokeAndWait(RunnableQueue.java:271)
        at GraphView.update(GraphView.java:862)
        at GraphView.update(GraphView.java:894)
        at GraphManager$5.gvtRenderingCompleted(GraphManager.java:692)
        at
org.apache.batik.swing.gvt.GVTTreeRenderer$4.dispatch(GVTTreeRenderer.java:192)
        at
org.apache.batik.util.EventDispatcher.dispatchEvent(EventDispatcher.java:102)
        at
org.apache.batik.util.EventDispatcher.fireEvent(EventDispatcher.java:86)
        at
org.apache.batik.util.EventDispatcher$1.run(EventDispatcher.java:45)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

"AWT-Shutdown" prio=5 tid=0x00aa6b90 nid=0xae4 in Object.wait()
[0x0372f000..0x0372fbe8]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1e035098> (a java.lang.Object)
        at java.lang.Object.wait(Unknown Source)
        at sun.awt.AWTAutoShutdown.run(Unknown Source)
        - locked <0x1e035098> (a java.lang.Object)
        at java.lang.Thread.run(Unknown Source)

"Thread-4" daemon prio=5 tid=0x02cddb48 nid=0x79c in Object.wait()
[0x0366f000..0x0366fb68]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1e035268> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x1e035268> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at org.apache.batik.util.CleanerThread.run(CleanerThread.java:102)

"Java Sound Event Dispatcher" daemon prio=5 tid=0x02ccf6c8 nid=0xbb8 in
Object.wait() [0x035ef000..0x035efa68]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1e0352e8> (a com.sun.media.sound.EventDispatcher)
        at java.lang.Object.wait(Unknown Source)
        at com.sun.media.sound.EventDispatcher.dispatchEvents(Unknown
Source)
        - locked <0x1e0352e8> (a com.sun.media.sound.EventDispatcher)
        at com.sun.media.sound.EventDispatcher.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

"Java2D Disposer" daemon prio=10 tid=0x00aa2008 nid=0xaa8 in Object.wait()
[0x0342f000..0x0342fae8]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1e035360> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x1e035360> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at sun.java2d.Disposer.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

"AWT-Windows" daemon prio=7 tid=0x02d33818 nid=0xf18 runnable
[0x033bf000..0x033bfb68]
        at sun.awt.windows.WToolkit.eventLoop(Native Method)
        at sun.awt.windows.WToolkit.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

"Low Memory Detector" daemon prio=5 tid=0x00a680f8 nid=0xebc runnable
[0x00000000..0x00000000]

"CompilerThread0" daemon prio=10 tid=0x00a66cd0 nid=0x970 waiting on
condition [0x00000000..0x02c2f6c0]

"Signal Dispatcher" daemon prio=10 tid=0x00a66018 nid=0xeec waiting on
condition [0x00000000..0x00000000]

"Finalizer" daemon prio=9 tid=0x00a39d70 nid=0xe90 in Object.wait()
[0x02baf000..0x02bafa68]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1e035568> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        - locked <0x1e035568> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(Unknown Source)
        at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" daemon prio=10 tid=0x00a62aa0 nid=0x364 in Object.wait()
[0x02b6f000..0x02b6fae8]
        at java.lang.Object.wait(Native Method)
        - waiting on <0x1e0355e8> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Unknown Source)
        at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
        - locked <0x1e0355e8> (a java.lang.ref.Reference$Lock)

"VM Thread" prio=10 tid=0x00a60de8 nid=0x724 runnable

"VM Periodic Task Thread" prio=10 tid=0x00a69308 nid=0xd88 waiting on
condition


Thanks,
Sudhakar
-- 
View this message in context: http://www.nabble.com/Problem-in-invokeAndWait-tf2124331.html#a5860794
Sent from the Batik - Users forum at Nabble.com.


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


Re: Problem in invokeAndWait

Posted by th...@kodak.com.
Hi Sudhakar,

Sudhakar S <ye...@hotmail.com> wrote on 08/24/2006 06:18:38 AM:

> >   So I am a little confused about this.  First your example shows this
> > being done in 'Main' which is not the Swing (AWT Event) thread.  There
> > would not be a problem with the above code using invokeAndWait.
> 
> I tried to give one example program. but by mistake i called update 
method
> in main. It is suppossed to be called from ?valueChanged? and 
?stateChanged?
> methods. 

   Ok.

> Yes. It may be ?valueChanged? or ?stateChanged?, once it is completed 
the
> update method then only it should execute the next statement.

> If I use third thread with invokeAndWait, it is running without getting
> struck. But it is not waiting to finish update()/render() to finish
> executing. So it is giving some problems in updating the objects in SVG
> Canvas.

    So you have two basic options:
        1) Move the code that is currently in valueChanged/stateChanged
           into the Runnable that runs in the UpdateManager Thread.  This
           can be a little tricky since you generally need to pull any
           data out of the Swing components up front (also you may find
           that you get updates 'piled up' in the UpdateManager).

        2) Modify your valueChanged/stateChanged methods so that they
           do nothing or 'delay' the action until the UpdateManager 
runnable
           completes.

           This is probably the 'better' of the two.  So I've written code
           that sets a Runnable that should be run in the AWT EventQueue
           when the current update completes.  This is a basic outline
           of the approach.

        bool runnableRunning;    // Set to true when you send a Runnable 
to UpdateManager
        NextRunnable nextRunnable;   // The runnable to run 
_in_the_swing_thread_ when current
                                        //  Update Manager runnable 
completes.

        // Returns true while this component has a runnable queued in 
UpdateManager
        public synchronized bool isUpdateRunning() {
           return runnableRunning;
        }

        // Used to send a runnable to the canvas's update manager
        // ensures that runnableRunning is set properly, and 
        // that updateFinished is called when it completes.
        public synchronized void startUpdate(final Runnable r) {
           runnableRunning = true;
           canvas.getUpdateManager().invokeLater(
                new Runnable() {
                        public void run() { r.run(); updateFinished(); 
}});
        }

        // Called when my runnable finishes in the UpdateManager
        // thread.  Sends 'queued' Swing work to the AWT Event queue.
        public synchronized void updateFinished() {
           runnableRunning = false;
           Runnable run = nextRunnable;
           nextRunnable = null;
           SwingUtilities.invokeLater(run);
        }

        public class NextRunnable implements Runnable() {
                NextRunnable nr;
                NextRunnable(NextRunnable nr) {
                        this.nr = nr;
                }
                public void run() {
                        // Do all the queued actions in order...
                        if (nr != null) nr.doAction();
                        doAction();

                        // push changes to Canvas at the end...
                        render();
                }
                public void doAction() { }
        }

        // If we have an update running then queue this
        // stateChanged event for processing after the
        // current update completes.
        public stateChanged(final ChangeEvent ce) {
           synchronized (this) {
                if (isUpdateRunning()) {
                    nextRunnable = new NextRunnable(nextRunnable) {
                        public void doAction() { doStateChanged(ce) }
                    }
                    return;  // we have queued our work for later.
                }
           }

           doStateChange(ce);
           render();
        }

        public void doStateChange(ChangeEvent ce) {
           // Do normal work from stateChange but not 'render'
        }

        I hope this helps....


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


Re: Problem in invokeAndWait

Posted by Sudhakar S <ye...@hotmail.com>.
Hi Thomas,

>   So I am a little confused about this.  First your example shows this
> being done in 'Main' which is not the Swing (AWT Event) thread.  There
> would not be a problem with the above code using invokeAndWait.  Do you
> call the above 'Main' from a Swing/AWT event handler?  If you are calling
> this from Swing/AWT, you should be able to move the call to Main 
> to another thread. 

I tried to give one example program. but by mistake i called update method
in main. It is suppossed to be called from “valueChanged” and “stateChanged”
methods. 

>   Also the above code doesn't make lots of sense to me. 
> Is the code performing an 'animation'?  (change a bunch
> of things, redraw, setup the next set of things, redraw, etc).

yes. My application can have ablity to move all the selected "ExBox" objects
in SVGCanvas.

>    Also you say '// Changing the SVG Elements attributes'
> however you can't modify the SVG elements outside of the 
> UpdateManager thread.  So if you are modifying the DOM
> you need to move those modifications into the update runnable.

Class ExBox {
  SetColor(){…};
  getColor(){…};
  setName(){…};
  getName(){…};
  setX(){…};
  getX(){…};
  setY(){…};
  getY(){…};
  .
  .
  .
}

Actually my application is having “ExBox” objects which is created using
external data. Sometimes “ExBox” objects may be in thousands. So after
created the “ExBox” objects my application draws all the objects in
SVGCanvas. While drawing, it will create one Image Element, one Text Element
and one Rectangle Element for each “ExBox” object. Element are named using
“ExBox” object name.
 
To update the “ExBox” objects in Canvas, After changed the “ExBox”
attributes’ values, it will call the update() method to update the new
changes in SVG Canvas. So whenever changes happening in “ExBox” objects’
attribute values, it calls update() method to update the SVG Document.

Public void update() { 

    try { 
            UpdateManager um = getUpdateManager(); 
            um.getUpdateRunnableQueue().invokeLater(new Runnable() { 
                public void run() { 
                    render(redraw); 
                } 
            }); 
        } catch (Exception ex) {} 
  } 

synchronized void render(boolean redraw) { 
  . 
  . 
  . 
for(int I = 0; I<exBoxes.length;I++) {

      ExBox exBox = exBoxes[i];

      Element nodeGrp = document.getElementById(exBox.getName());

      If(nodeGrp == null) {

      // It will create new Exbox object in SVG Canvas based on its
attributes
      .
      .
      .
      } else {

           //// It will update Exbox object in SVG Canvas based on its
attributes
      .
      .
      .
      }
}
} 

>  Synchronize can mean many things.  I think you mean that you 
> don't want the main thread to continue until the runnable in the 
> UpdateManager has completed. 

Yes. It may be “valueChanged” or “stateChanged”, once it is completed the
update method then only it should execute the next statement.

If I use third thread with invokeAndWait, it is running without getting
struck. But it is not waiting to finish update()/render() to finish
executing. So it is giving some problems in updating the objects in SVG
Canvas.

Please let me know, if you want somemore information.

Thanks,
Sudhakar

-- 
View this message in context: http://www.nabble.com/Problem-in-invokeAndWait-tf2124331.html#a5961196
Sent from the Batik - Users forum at Nabble.com.


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


Re: Problem in invokeAndWait

Posted by th...@kodak.com.
Hi Sudhakar,

Sudhakar S <ye...@hotmail.com> wrote on 08/22/2006 01:01:53 AM:

> > Please answer this question, or I can't help you: Why do you want 
> > the swing thread to block until the runnable completes?

>   Public static void main(String[] args) {
> 
>   ExApp app = new ExApp();
>   // Changing the SVG Elements attributes
>   ...
>   app.update();  // --------------------(1)
>   // Changing the SVG Elements attributes
>   ...
>   app.update();  // --------------------(2)
>   ...
>   }

> First ?app.update ()? will update/modify the elements? attributes based 
on
> the ?isChanged? flag. Since it is not synchronized with main thread, it 
will
> update and reset the flags based on statements, which are after first
> ?app.update ()?. So the second ?app.update ()? is not updating properly.

   So I am a little confused about this.  First your example shows this
being done in 'Main' which is not the Swing (AWT Event) thread.  There
would not be a problem with the above code using invokeAndWait.  Do you
call the above 'Main' from a Swing/AWT event handler?  If you are calling
this from Swing/AWT, you should be able to move the call to Main 
to another thread. 

   Also the above code doesn't make lots of sense to me. 
Is the code performing an 'animation'?  (change a bunch
of things, redraw, setup the next set of things, redraw, etc).

   Also you say '// Changing the SVG Elements attributes'
however you can't modify the SVG elements outside of the 
UpdateManager thread.  So if you are modifying the DOM
you need to move those modifications into the update runnable.

> Also I need to show the progress bar for completed status. So if it is
> ?synchronized? with main thread, it would be useful for me to resolve 
above
> problems.

   This is typically done by using SwingUtilities.invokeLater to
run code that updates a progress bar.  So after each 'app.update()'
you could use invokeLater to update your progress bar value.



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


Re: Problem in invokeAndWait

Posted by Sudhakar S <ye...@hotmail.com>.
Hi Thomas,

>  Synchronize can mean many things.  I think you mean that you
> don't want the main thread to continue until the runnable in the
> UpdateManager has completed.

Yes. This same thing I want in my application.

>  Synchronize can mean many things.  I think you mean that you
> don't want the main thread to continue until the runnable in the
> UpdateManager has completed.

Is there any work around to achieve this functionality?

> Please answer this question, or I can't help you: Why do you want 
> the swing thread to block until the runnable completes?

Class ExApp extends {

  Public void update() {

    try {
            UpdateManager um = getUpdateManager();
            um.getUpdateRunnableQueue().invokeLater(new Runnable() {
                public void run() {
                    render(redraw);
                }
            });
        } catch (Exception ex) {}
  }

  // render(false)  will create the Elements in the SVGDocument
  // render(true)  will update the Elements in the SVGDocument

  // Update will happen only for changed/modified elements. Since I am
having large 
  // amount elements, updating each element takes long time. So I have added
“isChanged” 
  // flag to check whether corresponding element to be modified or not. Once
the element is 
  // updated, the “isChanged” flag has been reset. So while calling “render”
method next 
  // time, it won’t redraw this element. It will modify based on “isChanged”
flag.

  synchronized void render(boolean redraw) {
  .
  .
  .
  }

  Public static void main(String[] args) {

  ExApp app = new ExApp();

  // Changing the SVG Elements attributes
  .
  .
  .
  app.update();  // --------------------(1)
  // Changing the SVG Elements attributes
  .
  .
  .
  app.update();  // --------------------(2)
  .
  .
  .
  }
}

First “app.update ()” will update/modify the elements’ attributes based on
the “isChanged” flag. Since it is not synchronized with main thread, it will
update and reset the flags based on statements, which are after first
“app.update ()”. So the second “app.update ()” is not updating properly.

Also I need to show the progress bar for completed status. So if it is
“synchronized” with main thread, it would be useful for me to resolve above
problems.

So please give better solutions to resolve my problems.

Thanks,
Sudhakar
-- 
View this message in context: http://www.nabble.com/Problem-in-invokeAndWait-tf2124331.html#a5919539
Sent from the Batik - Users forum at Nabble.com.


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


Re: Problem in invokeAndWait

Posted by th...@kodak.com.
Hi Sudhakar,

Sudhakar S <ye...@hotmail.com> wrote on 08/21/2006 10:24:47 AM:

  I repeat:

> >   You have to let the swing thread return.

> My requirement is that I should synchronize update
> thread(getUpdateManager().getUpdateRunnableQueue().invokeLater) with 
main
> thread. 

    Synchronize can mean many things.  I think you mean that you
don't want the main thread to continue until the runnable in the
UpdateManager has completed.

    This is incompatible with the architecture of Batik.  You
_must_ let the swing thread (what I believe you are calling your
"main thread") return otherwise Batik/Swing will lock up.

> > I don't know what you are trying to do so I can't suggest how to
> > do it.  Why do you want to block the swing thread until the
> > Runnable in the update manager completes?

  Please answer this question, or I can't help you: Why do you want 
the swing thread to block until the runnable completes?

> So I have created third thread with ?invokeAndWait?. Since it is
> called from third thread, I couldn?t synchronize it with main thread. So 
can
> you please tell how to synchronize  ?invokeAndWait? with my main thread?

   You are likely going to have to 'deconstruct' part of your
application.


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


Re: Problem in invokeAndWait

Posted by Sudhakar S <ye...@hotmail.com>.
Hi Thomas,

>   You have to let the swing thread return.
> I don't know what you are trying to do so I can't suggest how to
> do it.  Why do you want to block the swing thread until the
> Runnable in the update manager completes?

My requirement is that I should synchronize update
thread(getUpdateManager().getUpdateRunnableQueue().invokeLater) with main
thread. So I have created third thread with “invokeAndWait”. Since it is
called from third thread, I couldn’t synchronize it with main thread. So can
you please tell how to synchronize  “invokeAndWait” with my main thread?

Thanks,
Sudhakar
-- 
View this message in context: http://www.nabble.com/Problem-in-invokeAndWait-tf2124331.html#a5907797
Sent from the Batik - Users forum at Nabble.com.


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


Re: Problem in invokeAndWait

Posted by th...@kodak.com.
Hi Sudhakar,

Sudhakar S <ye...@hotmail.com> wrote on 08/18/2006 11:40:37 AM:

> >   The general solution to this problem is to introduce a third thread
> > that can safely call invokeAndWait and then run some code in the
> > Swing thread.
> 
> With third thread i can able to use "invokeAndWait". But if i tried to 
sync
> with main thread using "join", its again getting struck. So can you 
please
> explain bit more. so that i can sync with main thread.

   You have to let the swing thread return.
I don't know what you are trying to do so I can't suggest how to
do it.  Why do you want to block the swing thread until the
Runnable in the update manager completes?

   Do you know that you can call any function in the
Swing thread with SwingUtilities.invokeLater/invokeAndWait?
So you can call back to Swing when the Runnable completes
without having to wait in the Swing thread.


>  Thread t1 = new Thread(new Runnable() {
>             }); 
> 
>             t1.start();
>             t1.join();
> 
> >    Well you can synch it in this case but it would be more work.
> 
> Please give some more information to sync UpdateManager's thread with 
main
> thread to perform other operations in synchronized manner.
> 
> Thanks,
> Sudhakar
> -- 
> View this message in context: 
http://www.nabble.com/Problem-in-invokeAndWait-
> tf2124331.html#a5872078
> Sent from the Batik - Users forum at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: Problem in invokeAndWait

Posted by Sudhakar S <ye...@hotmail.com>.
Hi Thomas,

>   The general solution to this problem is to introduce a third thread
> that can safely call invokeAndWait and then run some code in the
> Swing thread.

With third thread i can able to use "invokeAndWait". But if i tried to sync
with main thread using "join", its again getting struck. So can you please
explain bit more. so that i can sync with main thread.

 Thread t1 = new Thread(new Runnable() {
                public void run() {
                    try {
                        UpdateManager um = getUpdateManager();
                        um.getUpdateRunnableQueue().invokeAndWait(new
Runnable() {
                            public void run() {
                                render(redrw);
                            }
                        });
                    } catch (Exception ex) {
                    }
                }
            });            
            
            t1.start();
            t1.join();

>    Well you can synch it in this case but it would be more work.

Please give some more information to sync UpdateManager's thread with main
thread to perform other operations in synchronized manner.

Thanks,
Sudhakar
-- 
View this message in context: http://www.nabble.com/Problem-in-invokeAndWait-tf2124331.html#a5872078
Sent from the Batik - Users forum at Nabble.com.


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


Re: Problem in invokeAndWait

Posted by th...@kodak.com.
Hi Sudhakar,

Sudhakar S <ye...@hotmail.com> wrote on 08/18/2006 12:16:17 AM:

> Using "invokeLater", it is working fine without any problem.
> But it is happening in separate thread, I couldn't synchronize with main
> thread. 

   Well you can synch it in this case but it would be more work.

> So changed "invokeLater" to "invokeAndWait". But after changed to
> "invokeAndWait", it is not at all drawing the shapes. It simply hangs. 
So I
> couldn?t find any solution to resolve this.

   It is very dangerous to call invokeAndWait from Swing thread (which is
what you are doing).  In some cases the renderer needs to query the 
Canvas which can only be done in the Swing thread.  It can't run code in
the Swing thread because you have it blocked waiting for the update
to complete.

   The general solution to this problem is to introduce a third thread
that can safely call invokeAndWait and then run some code in the
Swing thread.

   I should say that it is a really bad idea to lockup the Swing thread
for long periods anyway so this should improve your applications behavior
as the UI won't "Freeze" from extended periods any more.

> While go through the nabble threads related to ?invokeAndWait?, it told
> "updatecompleted" must be completed before calling ?invokeAndWait?. So 
can
> you please tell how to find whether updatecompleted is completed or not? 


   I don't think this is your problem:

> I have attached thread dump along with this mail.

> "RunnableQueue-0" daemon prio=7 tid=0x02cbcd30 nid=0xb78 in 
Object.wait()
> [0x036ef000..0x036efc68]
>         at java.lang.Object.wait(Native Method)
>         - waiting on <0x1d7dc310> (a 
java.awt.EventQueue$1AWTInvocationLock)
>         at java.lang.Object.wait(Unknown Source)
>         at java.awt.EventQueue.invokeAndWait(Unknown Source)
>         - locked <0x1d7dc310> (a java.awt.EventQueue$1AWTInvocationLock)
[....]
>         at 
org.apache.batik.util.RunnableQueue.run(RunnableQueue.java:203)
>         at java.lang.Thread.run(Unknown Source)
> 

> "AWT-EventQueue-0" prio=7 tid=0x02cfec30 nid=0xc78 in Object.wait()
> [0x0376f000..0x0376fb68]
[...]
>         at 
org.apache.batik.util.RunnableQueue.invokeAndWait(RunnableQueue.java:271)
[...]
>         at java.awt.EventQueue.dispatchEvent(Unknown Source)
>         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
> Source)
>         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
> Source)
>         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>         at java.awt.EventDispatchThread.run(Unknown Source)


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