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 vyang <vy...@apt-cafm.com> on 2007/08/23 21:47:43 UTC

invokelater thread issue?

Hello,

It seems I'm having some issue with invokelater threading.  I have a method
that does multiple invokelater calls.  It seems to work fine when this
method is called once, however when inside a loop it seems the invokelater
are called out of order.  This results in the text element being null when
the tspan tries to grab it.  My coding is as follows:

private void placeCellText() {
final TextBoxElement textBoxElement = new TextBoxElement(textBoxElementID,
elementName, 
                x, y, layer, null, textBoxAttribute);

textBoxElement.addNew(drawingPanel, parent.getConnection());  >> this method
calls invokelater which creates the text element

Vector textContentClone = (Vector)temp.clone();
                
while (textContentClone.size() > 0) {
     TextBoxElementContent firstTextBoxElementContent =
(TextBoxElementContent)textContentClone.remove(0);
     addTexts(textBoxElement, firstTextBoxElementContent); >> this method
calls invokelater which adds tspan element to text element above

     for (int i = 0; i < textContentClone.size(); i++) {

          if (firstTextBoxElementContent.getRow() ==
secondTextBoxElementContent.getRow()) {
          addTexts(textBoxElement, firstTextBoxElementContent); >> this
method calls invokelater which adds tspan element to text element above
          }
     }
}

Is there a way to make sure the first invokelater is done executing before
the next one begins.  Also is this a good way to use invokelater threading?

vyang
-- 
View this message in context: http://www.nabble.com/invokelater-thread-issue--tf4319567.html#a12300668
Sent from the Batik - Users mailing list archive 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: invokelater thread issue?

Posted by Archie Cobbs <ar...@awarix.com>.
This all doesn't make sense based on my understanding and experience, which
is that there is only one updater thread per JSVGComponent, and it processes
all actions registered with invokeLater() in the same order they are
registered.

FYI the relevant code is in org/apache/batik/util/RunnableQueue.java.

If someone can construct a counter-example (e.g., build an SVG document
programattically then print it out) that would be interesting to see...

On 8/23/07, Bishop, Michael W. CONTR J9C880 <Mi...@je.jfcom.mil>
wrote:
>
> I ran into a similar problem.  I could be wrong, so someone correct me,
> but I believe all the threads are STARTED in the order they are put in
> the RunnableQueue.  However, they could FINISH at different times.  If
> Thread A takes 10 seconds to run and Thread B takes 5 seconds, Thread B
> will finish before Thread A and could possibly cause the issues you're
> running into.
>
> My (not-so-elegant) solution was to modify the run() methods of my
> Threads to synchronize on the same object:
>
> public void run() {
>    synchronized(someCommonObject) {
>       ...
>    }
> }
>
> Michael Bishop
>
> -----Original Message-----
> From: vyang [mailto:vyang@apt-cafm.com]
> Sent: Thursday, August 23, 2007 3:48 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: invokelater thread issue?
>
>
> Hello,
>
> It seems I'm having some issue with invokelater threading.  I have a
> method that does multiple invokelater calls.  It seems to work fine when
> this method is called once, however when inside a loop it seems the
> invokelater are called out of order.  This results in the text element
> being null when the tspan tries to grab it.  My coding is as follows:
>
> private void placeCellText() {
> final TextBoxElement textBoxElement = new
> TextBoxElement(textBoxElementID, elementName,
>                 x, y, layer, null, textBoxAttribute);
>
> textBoxElement.addNew(drawingPanel, parent.getConnection());  >> this
> method calls invokelater which creates the text element
>
> Vector textContentClone = (Vector)temp.clone();
>
> while (textContentClone.size() > 0) {
>      TextBoxElementContent firstTextBoxElementContent =
> (TextBoxElementContent)textContentClone.remove(0);
>      addTexts(textBoxElement, firstTextBoxElementContent); >> this
> method calls invokelater which adds tspan element to text element above
>
>      for (int i = 0; i < textContentClone.size(); i++) {
>
>           if (firstTextBoxElementContent.getRow() ==
> secondTextBoxElementContent.getRow()) {
>           addTexts(textBoxElement, firstTextBoxElementContent); >> this
> method calls invokelater which adds tspan element to text element above
>           }
>      }
> }
>
> Is there a way to make sure the first invokelater is done executing
> before the next one begins.  Also is this a good way to use invokelater
> threading?
>
> vyang
> --
> View this message in context:
> http://www.nabble.com/invokelater-thread-issue--tf4319567.html#a12300668
> Sent from the Batik - Users mailing list archive 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
>
>


-- 
Archie L. Cobbs
CTO, Awarix, Inc.
http://www.awarix.com

RE: invokelater thread issue?

Posted by vyang <vy...@apt-cafm.com>.
Hello,

I've found a solution but I have not figured out the cause of the problem. 
I believe its something to do with threading as when I put the method inside
a swing worker it works out fine.  Without the swing worker, my variable
seems to reference the wrong object.  It seems the when the runnable runs,
the object inside the runnable is referencing the new object and not the one
that called it.  Like somehow the runnable replace the reference to the
first object with the second object.


thomas.deweese wrote:
> One thing that looked a little fishy was the id generation.

The id generation is just grabs a available # from the database.

vyang
-- 
View this message in context: http://www.nabble.com/invokelater-thread-issue--tf4319567.html#a12395333
Sent from the Batik - Users mailing list archive 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: invokelater thread issue?

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

vyang <vy...@apt-cafm.com> wrote on 08/27/2007 01:18:46 PM:

> Maybe its my misunderstanding of java or lack of understand of threads 
but,
> if I create a local variable in a loop, and thats the variable thats 
called
> in the runnable.  Now if my loop executes a second time before my 
runnable
> runs, which creates another local variable of same name/type, will the
> runnable call the first variable or the second one(does the variable get
> overriden)?

   No but I'm guessing that somewhere in your code you end up grabbing
state from the second loop instead of the first.  One thing that looked
a little fishy was the id generation.

   I tried to look at your code but the snippets were just to fragmented
for me to figure out where the error might be.

> thomas.deweese wrote:
> > 
> > Hi Vyang,
> > 
> > vyang <vy...@apt-cafm.com> wrote on 08/24/2007 12:08:44 PM:
> > 
> >> Sorry, I meant to post the code but went and debug some more and 
forgot
> >> about it.  It seems that the first runnable(one from the first loop) 
> > call to
> >> create the tspan grabs the next element(ie second loops element) and 
not 
> > the
> >> one that called it.
> > 
> >    So you have your problem solved?  You need to update your code so
> > the Runnable know's what text element called it...
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/invokelater-
> thread-issue--tf4319567.html#a12353574
> Sent from the Batik - Users mailing list archive 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: invokelater thread issue?

Posted by vyang <vy...@apt-cafm.com>.
Hello,

Maybe its my misunderstanding of java or lack of understand of threads but,
if I create a local variable in a loop, and thats the variable thats called
in the runnable.  Now if my loop executes a second time before my runnable
runs, which creates another local variable of same name/type, will the
runnable call the first variable or the second one(does the variable get
overriden)?

vyang


thomas.deweese wrote:
> 
> Hi Vyang,
> 
> vyang <vy...@apt-cafm.com> wrote on 08/24/2007 12:08:44 PM:
> 
>> Sorry, I meant to post the code but went and debug some more and forgot
>> about it.  It seems that the first runnable(one from the first loop) 
> call to
>> create the tspan grabs the next element(ie second loops element) and not 
> the
>> one that called it.
> 
>    So you have your problem solved?  You need to update your code so
> the Runnable know's what text element called it...
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/invokelater-thread-issue--tf4319567.html#a12353574
Sent from the Batik - Users mailing list archive 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: invokelater thread issue?

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

vyang <vy...@apt-cafm.com> wrote on 08/24/2007 12:08:44 PM:

> Sorry, I meant to post the code but went and debug some more and forgot
> about it.  It seems that the first runnable(one from the first loop) 
call to
> create the tspan grabs the next element(ie second loops element) and not 
the
> one that called it.

   So you have your problem solved?  You need to update your code so
the Runnable know's what text element called it...


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


RE: invokelater thread issue?

Posted by vyang <vy...@apt-cafm.com>.
Hello,

Sorry, I meant to post the code but went and debug some more and forgot
about it.  It seems that the first runnable(one from the first loop) call to
create the tspan grabs the next element(ie second loops element) and not the
one that called it.  Here is the code(sorry its so messy):

private void jButtonInsertActionPerformed(java.awt.event.ActionEvent evt) {                                              
        final DrawingPanel drawingPanel = main.getActiveDrawingPanel();
        
        ListIterator<APTElement> li =
main.getActiveDrawing().getSelectedAPTElements().listIterator();
        
while (li.hasNext()) {
            	APTElement aptElement = li.next();
            	System.out.println("id: " + aptElement.getElementId());
            	Point2D.Double dataNode = aptElement.getDataNode();
           		final double x = dataNode.getX();
            	final double y = dataNode.getY();

drawingPanel.placeTextBySelection(finalTextPanel, x, y);
}
}

public void placeTextBySelection(TextPanel textPanel, double x, double y) {
        if (textPanel.isCell()) {
            Vector textContent = textPanel.getTextCellContent();
            
            if (textContent.size() > 0)
                placeCellText(textPanel, textContent, x, y);
        } else {
            TextBoxElementContent textBoxElementContent =
textPanel.getNoteTextBoxElementContent();
            
            if (textBoxElementContent != null)
                placeNoteText(textPanel, textBoxElementContent, x, y);
        }
    }

private void placeCellText(TextPanel textPanel, Vector textContent, double
x, double y) {
        final Layer layer = addLayerToDrawing(textPanel.getLayerName());
        
        if(layer.isLocked()){
            SwingUtilities.invokeLater(new Runnable(){
                public void run(){
                    JOptionPane.showMessageDialog(parent, "Icon's target
layer, " +
                            layer.getLayerName() + ", is locked!");
                }
            });
            return;
        }
        
        long textBoxElementID = -1;
        
        try{
            textBoxElementID =
APTElement.getNextElementId(parent.getConnection());
        }
        catch(SQLException sql){
            JOptionPane.showMessageDialog(parent, "SQL Error getting next
available " +
                    "elementId for new TextBox: " + sql.getMessage());
            parent.safeExit();
        }
        
        String elementName = layer.getLayerName() + "_" +
Long.toString(textBoxElementID);
        
        Attribute textBoxAttribute = textPanel.getSelectedAttribute();
        
        TextBoxElement textBoxElement = new TextBoxElement(textBoxElementID,
elementName, 
                x, y, layer, null, textBoxAttribute);
        System.out.println("textBoxElement id: " +
textBoxElement.getElementId());
        final DrawingPanel finalDrawingPanel = this;
        final Vector temp = textContent;
        final Connection con = parent.getConnection();
        final DrawingPanel dp = this;
        
                    textBoxElement.addNew(finalDrawingPanel,
parent.getConnection());  //see method below
                } catch(SQLException sqlex){
                    sqlex.printStackTrace();
                    JOptionPane.showMessageDialog(parent, "SQL Error adding
TextBox Element: " +
                            sqlex.getMessage());
                    parent.safeExit();
                }
                
                SVGDocument doc =
textBoxElement.getLayer().getDrawing().getSVGDocument();
                Element element =
doc.getElementById(Long.toString(textBoxElement.getElementId()));
                System.out.println("element: " + element);
                
                final Vector textContentClone = (Vector)temp.clone();
                
                while (textContentClone.size() > 0) {
                    System.out.println("begin while " +
textBoxElement.getElementId());
                    final TextBoxElementContent firstTextBoxElementContent =
(TextBoxElementContent)textContentClone.remove(0);
                    
                   
textBoxElement.addTextBoxElementContentToTextBoxElement(firstTextBoxElementContent);
                    addTexts(textBoxElement, firstTextBoxElementContent);
//see method below
                    
                    for (int i = 0; i < textContentClone.size(); i++) {
                        System.out.println("begin for " +
textBoxElement.getElementId());
                        final TextBoxElementContent
secondTextBoxElementContent =
(TextBoxElementContent)textContentClone.elementAt(i);
                        
                        if (firstTextBoxElementContent.getRow() ==
secondTextBoxElementContent.getRow()) {
                           
textContentClone.remove(secondTextBoxElementContent);
                            
                           
textBoxElement.addTextBoxElementContentToTextBoxElement(secondTextBoxElementContent);
                            addTexts(textBoxElement,
secondTextBoxElementContent);
                            
                            break;
                        }
                        System.out.println("end for " +
textBoxElement.getElementId());
                    }
                    System.out.println("end while " +
textBoxElement.getElementId());
                }

final TextBoxElement finalTextBoxElement = textBoxElement;

getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable(){
            public void run(){
                System.out.println("begin last runnable " +
finalTextBoxElement.getElementId());
                //update the text box dimensions
                finalTextBoxElement.wrapCellTextBoxToContents();
                
                //recenter the datanode
                Point2D.Double centroid = finalTextBoxElement.getCentroid();
                finalTextBoxElement.getDataNode().setLocation(centroid);
                
                try{
                    finalTextBoxElement.update(dp, con);
                    con.commit();
                    con.setAutoCommit(true);
                } catch(SQLException s){
                    s.printStackTrace();
                    JOptionPane.showMessageDialog(parent, "SQL error
updating " +
                            "text box: " + s.getMessage());
                    parent.safeExit();
                }
                System.out.println("end last runnable " +
finalTextBoxElement.getElementId());
                dp.setIsThreadFinish(true);
            }
        });
}

//textBoxElement.addnew
public void addNew(JSVGCanvas canvas, Connection con) throws SQLException{
        if(con != null){
            boolean conStatus = con.getAutoCommit();
            
            if(conStatus){
                con.setAutoCommit(false);
            }
            
            super.addNew(con);
            TextBoxElementDA.addNew(this, con);
            
            if(conStatus){
                con.commit();
                con.setAutoCommit(true);
            }
        }
                
        //update SVG; if canvas isn't null update via update manager  
        if(canvas == null){
            TextBoxElementSVGDA.addNew(this);
        }
        else{
            final TextBoxElement me = this;
            
//            try {
//           
canvas.getUpdateManager().getUpdateRunnableQueue().invokeAndWait(new
Runnable() {
           
canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable(){
                public void run(){
//this addnew method in here just acces svg and creates the text element no
more runnable in here
                    System.out.println("b4 TextBoxElementSVGDA.addNew(me) "
+ me.getElementId());
                    TextBoxElementSVGDA.addNew(me);
                    System.out.println("after TextBoxElementSVGDA.addNew(me)
" +  me.getElementId());
                }
            });
}
}

 private void addTexts(TextBoxElement textBoxElement, TextBoxElementContent
textBoxElementContent) {
        System.out.println("begin addTexts " +
textBoxElement.getElementId());
        if (textBoxElementContent instanceof TextBoxElementRecordContent){
            TextBoxElementRecordContent textBoxElementRecordContent =
(TextBoxElementRecordContent)textBoxElementContent;
            
            APTElement spaceElement;
            
            try {
                spaceElement = getSpaceElement(textBoxElement);
               
textBoxElementRecordContent.setRefId(spaceElement.getElementId());
               
textBoxElementRecordContent.refreshText(parent.getConnection());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        
        try{
            Connection con = parent.getConnection();
            DrawingPanel dp = this;
            
            con.setAutoCommit(false);
            
            textBoxElementContent.addNew(dp, con, true);  //see method below
            
            final TextBoxElementContent finalTextBoxElementContent =
textBoxElementContent;
            
            //update the text box and contents
            dp.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable(){
                public void run(){
                    System.out.println("b4
finalTextBoxElementContent.refreshComputedWidth() " +
finalTextBoxElementContent.getTextBoxElement().getElementId());
                    //update the computed text width for the new content
                    finalTextBoxElementContent.refreshComputedWidth();
                    System.out.println("after
finalTextBoxElementContent.refreshComputedWidth() " +
finalTextBoxElementContent.getTextBoxElement().getElementId());
                }
            });
        } catch(SQLException sqlex){
            sqlex.printStackTrace();
            JOptionPane.showMessageDialog(parent, "SQL Error adding new text
content to " +
                    "text box: " + sqlex.getMessage());
            parent.safeExit();
        }
        System.out.println("end addTexts " + textBoxElement.getElementId());
    }

//textBoxElementContent.addNew
public void addNew(final JSVGCanvas canvas, final Connection con, 
        boolean updateSVG) throws SQLException{
        System.out.println("begin TextBoxElementContent addnew " +
getTextBoxElement().getElementId());
        if(con != null){
            TextBoxElementContentDA.addNew(this, con);
        }
        
        //update SVG; if canvas isn't null update via update manager
        if(!updateSVG){
            return;
        }
        
        if(canvas == null){
            TextBoxElementContentSVGDA.addNew(this);            
        }
        else{
            final TextBoxElementContent me = this;
            
           
canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable(){
                public void run(){
//this method just access svg and creates the tspan element no more runnable
access
                    System.out.println("b4
TextBoxElementContentSVGDA.addNew(me) " +
me.getTextBoxElement().getElementId());
                    TextBoxElementContentSVGDA.addNew(me);
                    System.out.println("after
TextBoxElementContentSVGDA.addNew(me) " +
me.getTextBoxElement().getElementId());
                }
            });            
        }
        System.out.println("end TextBoxElementContent addnew " +
getTextBoxElement().getElementId());
    }
-- 
View this message in context: http://www.nabble.com/invokelater-thread-issue--tf4319567.html#a12315257
Sent from the Batik - Users mailing list archive 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: invokelater thread issue?

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

vyang <vy...@apt-cafm.com> wrote on 08/24/2007 09:39:30 AM:

> If thats the case, could you look at my code and see what I'm doing 
wrong. 
> As the second time through my loop, I get a empty element.

   None of the code you provided is useful for determining why
you get an empty element.  You don't show how you are calling invokeLater
or the code in the runnable passed to invokeLater.


> 
> vyang
> 
> 
> 
> thomas.deweese wrote:
> > 
> > Hi Michael,
> > 
> > "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote 
on 
> > 08/23/2007 04:08:25 PM:
> > 
> >> I ran into a similar problem.  I could be wrong, so someone correct 
me,
> >> but I believe all the threads are STARTED in the order they are put 
in
> >> the RunnableQueue.
> > 
> >    All Runnables added to the runnable queue are run in a single
> > thread in the order that they are added.
> > 
> >> However, they could FINISH at different times.
> > 
> >    The run methods of your Runnable will finish in the order 
> > they were submitted and previous runnables run method must finish 
> > before the next run method starts.
> > 
> >> If Thread A takes 10 seconds to run and Thread B takes 5 seconds, 
Thread 
> > B
> >> will finish before Thread A and could possibly cause the issues 
you're
> >> running into.
> > 
> >     If this really happened it would indicate a serious bug in the 
code.
> > A Runnnable could start a separate thread (or run something in another
> > suitable thread like swing) and unless the RunnableQueue runnable 
waited
> > for the other thread to complete you could get behavior that looked a
> > lot like this.
> > 
> >> My (not-so-elegant) solution was to modify the run() methods of my
> >> Threads to synchronize on the same object:
> >> 
> >> public void run() {
> >>    synchronized(someCommonObject) {
> >>       ...
> >>    }
> >> }
> >> 
> >> Michael Bishop
> >> 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/invokelater-
> thread-issue--tf4319567.html#a12312623
> Sent from the Batik - Users mailing list archive 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: invokelater thread issue?

Posted by vyang <vy...@apt-cafm.com>.
Hello,

>The run methods of your Runnable will finish in the order 
>they were submitted and previous runnables run method must finish 
>before the next run method starts.

If thats the case, could you look at my code and see what I'm doing wrong. 
As the second time through my loop, I get a empty element.

vyang



thomas.deweese wrote:
> 
> Hi Michael,
> 
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on 
> 08/23/2007 04:08:25 PM:
> 
>> I ran into a similar problem.  I could be wrong, so someone correct me,
>> but I believe all the threads are STARTED in the order they are put in
>> the RunnableQueue.
> 
>    All Runnables added to the runnable queue are run in a single
> thread in the order that they are added.
> 
>> However, they could FINISH at different times.
> 
>    The run methods of your Runnable will finish in the order 
> they were submitted and previous runnables run method must finish 
> before the next run method starts.
> 
>> If Thread A takes 10 seconds to run and Thread B takes 5 seconds, Thread 
> B
>> will finish before Thread A and could possibly cause the issues you're
>> running into.
> 
>     If this really happened it would indicate a serious bug in the code.
> A Runnnable could start a separate thread (or run something in another
> suitable thread like swing) and unless the RunnableQueue runnable waited
> for the other thread to complete you could get behavior that looked a
> lot like this.
> 
>> My (not-so-elegant) solution was to modify the run() methods of my
>> Threads to synchronize on the same object:
>> 
>> public void run() {
>>    synchronized(someCommonObject) {
>>       ...
>>    }
>> }
>> 
>> Michael Bishop
>> 
> 

-- 
View this message in context: http://www.nabble.com/invokelater-thread-issue--tf4319567.html#a12312623
Sent from the Batik - Users mailing list archive 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: invokelater thread issue?

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Thu, 2007-08-23 at 16:08 -0400, Bishop, Michael W. CONTR J9C880
wrote:
> I ran into a similar problem.  I could be wrong, so someone correct me,
> but I believe all the threads are STARTED in the order they are put in
> the RunnableQueue.  However, they could FINISH at different times.  If
> Thread A takes 10 seconds to run and Thread B takes 5 seconds, Thread B
> will finish before Thread A and could possibly cause the issues you're
> running into.
> 
> My (not-so-elegant) solution was to modify the run() methods of my
> Threads to synchronize on the same object:
> 
> public void run() {
>    synchronized(someCommonObject) {
>       ...
>    }
> }
> 

As usual, always run SVG DOC modification using updateManager, do not
construct your own Thread, use the supplied updateManager thread.

Regards
Tonny Kohar
-- 
Inspiration and Expression
http://blogs.kiyut.com/tonny/


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


RE: invokelater thread issue?

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

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on 
08/23/2007 04:08:25 PM:

> I ran into a similar problem.  I could be wrong, so someone correct me,
> but I believe all the threads are STARTED in the order they are put in
> the RunnableQueue.

   All Runnables added to the runnable queue are run in a single
thread in the order that they are added.

> However, they could FINISH at different times.

   The run methods of your Runnable will finish in the order 
they were submitted and previous runnables run method must finish 
before the next run method starts.

> If Thread A takes 10 seconds to run and Thread B takes 5 seconds, Thread 
B
> will finish before Thread A and could possibly cause the issues you're
> running into.

    If this really happened it would indicate a serious bug in the code.
A Runnnable could start a separate thread (or run something in another
suitable thread like swing) and unless the RunnableQueue runnable waited
for the other thread to complete you could get behavior that looked a
lot like this.

> My (not-so-elegant) solution was to modify the run() methods of my
> Threads to synchronize on the same object:
> 
> public void run() {
>    synchronized(someCommonObject) {
>       ...
>    }
> }
> 
> Michael Bishop
> 
> -----Original Message-----
> From: vyang [mailto:vyang@apt-cafm.com] 
> Sent: Thursday, August 23, 2007 3:48 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: invokelater thread issue?
> 
> 
> Hello,
> 
> It seems I'm having some issue with invokelater threading.  I have a
> method that does multiple invokelater calls.  It seems to work fine when
> this method is called once, however when inside a loop it seems the
> invokelater are called out of order.  This results in the text element
> being null when the tspan tries to grab it.  My coding is as follows:
> 
> private void placeCellText() {
> final TextBoxElement textBoxElement = new
> TextBoxElement(textBoxElementID, elementName, 
>                 x, y, layer, null, textBoxAttribute);
> 
> textBoxElement.addNew(drawingPanel, parent.getConnection());  >> this
> method calls invokelater which creates the text element
> 
> Vector textContentClone = (Vector)temp.clone();
> 
> while (textContentClone.size() > 0) {
>      TextBoxElementContent firstTextBoxElementContent =
> (TextBoxElementContent)textContentClone.remove(0);
>      addTexts(textBoxElement, firstTextBoxElementContent); >> this
> method calls invokelater which adds tspan element to text element above
> 
>      for (int i = 0; i < textContentClone.size(); i++) {
> 
>           if (firstTextBoxElementContent.getRow() ==
> secondTextBoxElementContent.getRow()) {
>           addTexts(textBoxElement, firstTextBoxElementContent); >> this
> method calls invokelater which adds tspan element to text element above
>           }
>      }
> }
> 
> Is there a way to make sure the first invokelater is done executing
> before the next one begins.  Also is this a good way to use invokelater
> threading?
> 
> vyang
> --
> View this message in context:
> http://www.nabble.com/invokelater-thread-issue--tf4319567.html#a12300668
> Sent from the Batik - Users mailing list archive 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
> 


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


RE: invokelater thread issue?

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
I ran into a similar problem.  I could be wrong, so someone correct me,
but I believe all the threads are STARTED in the order they are put in
the RunnableQueue.  However, they could FINISH at different times.  If
Thread A takes 10 seconds to run and Thread B takes 5 seconds, Thread B
will finish before Thread A and could possibly cause the issues you're
running into.

My (not-so-elegant) solution was to modify the run() methods of my
Threads to synchronize on the same object:

public void run() {
   synchronized(someCommonObject) {
      ...
   }
}

Michael Bishop

-----Original Message-----
From: vyang [mailto:vyang@apt-cafm.com] 
Sent: Thursday, August 23, 2007 3:48 PM
To: batik-users@xmlgraphics.apache.org
Subject: invokelater thread issue?


Hello,

It seems I'm having some issue with invokelater threading.  I have a
method that does multiple invokelater calls.  It seems to work fine when
this method is called once, however when inside a loop it seems the
invokelater are called out of order.  This results in the text element
being null when the tspan tries to grab it.  My coding is as follows:

private void placeCellText() {
final TextBoxElement textBoxElement = new
TextBoxElement(textBoxElementID, elementName, 
                x, y, layer, null, textBoxAttribute);

textBoxElement.addNew(drawingPanel, parent.getConnection());  >> this
method calls invokelater which creates the text element

Vector textContentClone = (Vector)temp.clone();
                
while (textContentClone.size() > 0) {
     TextBoxElementContent firstTextBoxElementContent =
(TextBoxElementContent)textContentClone.remove(0);
     addTexts(textBoxElement, firstTextBoxElementContent); >> this
method calls invokelater which adds tspan element to text element above

     for (int i = 0; i < textContentClone.size(); i++) {

          if (firstTextBoxElementContent.getRow() ==
secondTextBoxElementContent.getRow()) {
          addTexts(textBoxElement, firstTextBoxElementContent); >> this
method calls invokelater which adds tspan element to text element above
          }
     }
}

Is there a way to make sure the first invokelater is done executing
before the next one begins.  Also is this a good way to use invokelater
threading?

vyang
--
View this message in context:
http://www.nabble.com/invokelater-thread-issue--tf4319567.html#a12300668
Sent from the Batik - Users mailing list archive 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