Hi all,
I am now testing coming 2.0.1 release of Pivot libraries with my desktop
application developed during previous year on Pivot 2.0 and am facing
one great problem with threads :-(
Every task which loads data at background and worked in 2.0 well now
throws exception like this:
java.lang.IllegalStateException: this method can only be called from the
AWT event dispatch thread, and not from "Thread-26"
at org.apache.pivot.wtk.Container$1.check(Container.java:872)
at
org.apache.pivot.wtk.Container.assertEventDispatchThread(Container.java:880)
at org.apache.pivot.wtk.Component.repaint(Component.java:2047)
at org.apache.pivot.wtk.Component.repaint(Component.java:1998)
at
org.apache.pivot.wtk.skin.ComponentSkin.repaintComponent(ComponentSkin.java:351)
at
org.apache.pivot.wtk.skin.ComponentSkin.repaintComponent(ComponentSkin.java:346)
at
org.apache.pivot.wtk.skin.terra.TerraTableViewSkin.enabledChanged(TerraTableViewSkin.java:1394)
at
org.apache.pivot.wtk.Component$ComponentStateListenerList.enabledChanged(Component.java:399)
at org.apache.pivot.wtk.Component.setEnabled(Component.java:2173)
at cz.cgrim.alchemist.dql.RunQueryTask.execute(RunQueryTask.java:58)
at cz.cgrim.alchemist.dql.RunQueryTask.execute(RunQueryTask.java:23)
at
org.apache.pivot.util.concurrent.Task$ExecuteCallback.run(Task.java:42)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.lang.Thread.run(Thread.java:722)
In this example at first it disables TableView (to disable user
interaction during background load of data), than it loaded results from
DQL query into that TableView and at the end it enabled that TableView.
I have tens of use cases with similar approach in my application used to
load data at background because it can take long time to finish while
user can work on another tasks.
Another equal problem with thread has occurred for example in my custom
Log4J Appender:
Exception in thread "Timer-2" java.lang.IllegalStateException: this
method can only be called from the AWT event dispatch thread, and not
from "Timer-2"
at org.apache.pivot.wtk.Container$1.check(Container.java:872)
at
org.apache.pivot.wtk.Container.assertEventDispatchThread(Container.java:880)
at org.apache.pivot.wtk.Component.invalidate(Component.java:1955)
at
org.apache.pivot.wtk.skin.ComponentSkin.invalidateComponent(ComponentSkin.java:340)
at
org.apache.pivot.wtk.skin.TextAreaSkinParagraphView.textRemoved(TextAreaSkinParagraphView.java:419)
at
org.apache.pivot.wtk.TextArea$Paragraph$ParagraphListenerList.textRemoved(TextArea.java:55)
at
org.apache.pivot.wtk.TextArea$Paragraph.removeText(TextArea.java:153)
at org.apache.pivot.wtk.TextArea.insertText(TextArea.java:757)
at org.apache.pivot.wtk.TextArea.insertText(TextArea.java:730)
at
cz.cgrim.alchemist.logger.TextAreaAppender.append(TextAreaAppender.java:41)
at
org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
at
org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
at org.apache.log4j.Category.callAppenders(Category.java:206)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.log(Category.java:856)
at com.documentum.fc.common.DfLogger.warn(DfLogger.java:151)
at
com.documentum.fc.client.impl.bof.cache.ClassCacheManager$CacheCleanupTask.run(ClassCacheManager.java:602)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Here I simply implement AppenderSkeleton and append every line from
LoggingEvent into Pivot's TextPane. Log4J runs it in separate thread.
Please, is now there another approach how to use threads and Pivot's
Task to do changes in GUI or is it a bug? In 2.0 release everything
spoken here worked like a charm.
Thanks for an advance.
Lukas Machacek