Pivot
  1. Pivot
  2. PIVOT-780

Can't use BXMLSerializer from non-AWT threads makes background resource loading impossible

    Details

      Description

      Calling bxmlSerializer.readObject from a non-AWT thread causes the following exception:

      An error occurred at line number 5 in file /C:/Users/Piotr/Projekty/viungo/viungo-editor/target/scala_2.9.0/classes/com/viungo/editor/CircuitEditor.bxml:
      org.apache.pivot.serialization.SerializationException: java.lang.IllegalStateException: this method can only be called from the AWT event dispatch thread
      at org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:769)
      at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:441)
      at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:624)
      at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:579)
      at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:540)
      at com.viungo.editor.CircuitEditor$$anon$1.execute(CircuitEditor.scala:21)
      at com.viungo.editor.CircuitEditor$$anon$1.execute(CircuitEditor.scala:18)
      at org.apache.pivot.util.concurrent.Task$ExecuteCallback.run(Task.java:42)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at java.lang.Thread.run(Thread.java:662)
      Caused by: java.lang.IllegalStateException: this method can only be called from the AWT event dispatch thread
      at org.apache.pivot.wtk.Container$1.run(Container.java:864)
      at org.apache.pivot.wtk.Container.assertEventDispatchThread(Container.java:871)
      at org.apache.pivot.wtk.WTKListenerList.add(WTKListenerList.java:36)
      at org.apache.pivot.wtk.skin.ComponentSkin.install(ComponentSkin.java:96)
      at org.apache.pivot.wtk.skin.ContainerSkin.install(ContainerSkin.java:129)
      at org.apache.pivot.wtk.skin.WindowSkin.install(WindowSkin.java:66)
      at org.apache.pivot.wtk.Component.setSkin(Component.java:749)
      at org.apache.pivot.wtk.Component.installSkin(Component.java:812)
      at org.apache.pivot.wtk.Window.<init>(Window.java:453)
      at org.apache.pivot.wtk.Window.<init>(Window.java:448)
      at com.viungo.editor.EditorWindow.<init>(EditorWindow.scala:20)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      at java.lang.Class.newInstance0(Class.java:355)
      at java.lang.Class.newInstance(Class.java:308)
      at org.apache.pivot.beans.BXMLSerializer.newTypedObject(BXMLSerializer.java:1556)
      at org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:767)
      ... 11 more

      Loading objects in background is very important, so that the user can see e.g. a progress indicator while the rest of the UI is deserialized.
      Doing this in AWT thread, blocks what is currently displayed.

        Issue Links

          Activity

          Hide
          Noel Grandin added a comment -

          Marking this as closed for now. Can be re-opened if there is some corner case we missed.

          Show
          Noel Grandin added a comment - Marking this as closed for now. Can be re-opened if there is some corner case we missed.
          Hide
          Chris Bartlett added a comment -

          I haven't had a chance to test this yet. Perhaps Piotr or others have?

          Show
          Chris Bartlett added a comment - I haven't had a chance to test this yet. Perhaps Piotr or others have?
          Hide
          Sandro Martini added a comment -

          Noel (and others),
          can we mark this as resolved now ?

          Show
          Sandro Martini added a comment - Noel (and others), can we mark this as resolved now ?
          Hide
          Noel Grandin added a comment -

          Checked in a fix in rev 1153866

          Show
          Noel Grandin added a comment - Checked in a fix in rev 1153866
          Hide
          Noel Grandin added a comment -

          Modifying any WTK object from outside the event thread could lead to data-corruption, which tends to show up as weird errors far away from the misbehaving code.
          That is why we try to catch the offending code early on, to save ourselves from that debugging.

          You can already override the check - see Container#setEventDispatchThreadChecker()

          Show
          Noel Grandin added a comment - Modifying any WTK object from outside the event thread could lead to data-corruption, which tends to show up as weird errors far away from the misbehaving code. That is why we try to catch the offending code early on, to save ourselves from that debugging. You can already override the check - see Container#setEventDispatchThreadChecker()
          Hide
          Chris Bartlett added a comment - - edited

          Noel - The Display check sounds good to me, but as mentioned elsewhere I would prefer the EDT check to be optional if it makes sense.

          Is the purpose to prevent threading issues like deadlocks, or just to ensure that updates will be visible without an explicit repaint or some kind of layout change, or something else?

          Show
          Chris Bartlett added a comment - - edited Noel - The Display check sounds good to me, but as mentioned elsewhere I would prefer the EDT check to be optional if it makes sense. Is the purpose to prevent threading issues like deadlocks, or just to ensure that updates will be visible without an explicit repaint or some kind of layout change, or something else?
          Hide
          Chris Bartlett added a comment -

          Linked to related issues for improved context

          Show
          Chris Bartlett added a comment - Linked to related issues for improved context
          Hide
          Noel Grandin added a comment -

          We could weaken the check so that it reads like this:

          if (the component is attached to a Display
          AND this thread is not the event dispatch thread)

          { throw exception }

          that would allow background loading, whilst still catching problems with modifying currently "live" components from outside the EDT.

          Show
          Noel Grandin added a comment - We could weaken the check so that it reads like this: if (the component is attached to a Display AND this thread is not the event dispatch thread) { throw exception } that would allow background loading, whilst still catching problems with modifying currently "live" components from outside the EDT.
          Hide
          Greg Brown added a comment -

          This has nothing to do with BXMLSerializer. You'd run into the same problem if you created components programmatically on a background thread.

          Show
          Greg Brown added a comment - This has nothing to do with BXMLSerializer. You'd run into the same problem if you created components programmatically on a background thread.
          Hide
          Sandro Martini added a comment -

          >Wasn't there some discussion about allowing a caller to disable these EDT checks?
          Yes, and should be this issue (already closed for 2.0.1): https://issues.apache.org/jira/browse/PIVOT-747
          maybe Noel can have more info.
          But I'd like to have a way (or a flag or something other) to turn this off (default on) in BXMLSerializer, what do you think ?

          Bye

          Show
          Sandro Martini added a comment - >Wasn't there some discussion about allowing a caller to disable these EDT checks? Yes, and should be this issue (already closed for 2.0.1): https://issues.apache.org/jira/browse/PIVOT-747 maybe Noel can have more info. But I'd like to have a way (or a flag or something other) to turn this off (default on) in BXMLSerializer, what do you think ? Bye
          Hide
          Greg Brown added a comment -

          Wasn't there some discussion about allowing a caller to disable these EDT checks?

          Show
          Greg Brown added a comment - Wasn't there some discussion about allowing a caller to disable these EDT checks?
          Hide
          Sandro Martini added a comment -

          We have to verify what to do with this (fix or if won't fix), and if fix in 2.0.1 or in 2.1 (maybe providing an extension of BXMLSerializer for handling this).

          Show
          Sandro Martini added a comment - We have to verify what to do with this (fix or if won't fix), and if fix in 2.0.1 or in 2.1 (maybe providing an extension of BXMLSerializer for handling this).
          Hide
          Chris Bartlett added a comment - - edited

          This sounds like it is related to PIVOT-740 / r1101054
          http://svn.apache.org/viewvc?view=revision&revision=1101054

          Show
          Chris Bartlett added a comment - - edited This sounds like it is related to PIVOT-740 / r1101054 http://svn.apache.org/viewvc?view=revision&revision=1101054

            People

            • Assignee:
              Noel Grandin
              Reporter:
              Piotr Kołaczkowski
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development