[groovy-user] GroovyFx Thread

20 views
Skip to first unread message

Naveedur Rahman

unread,
Jan 4, 2012, 6:11:15 AM1/4/12
to us...@groovy.codehaus.org, Jim Clarke
Hi All,

       How can i use thread in groovyFx to run the process in the background.

       if(login.contains("SUCCESS")){  
         sceneGB.defer(){
           showPageContents()
         }
         sceneGB.defer(){
             showProgress()
          }
      }


       In the above script i tried to display progress while pageContent is loading but it is not showing the progress, and the Window gets hanged until the showPageContents() is loaded.

      How can i display the progress on the window till the page is loaded.  And I also checked by using thread but its throwing the following error


Exception in thread "Thread-10" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-10
    at com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source)
    at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown Source)
    at javafx.scene.Parent$1.onProposedChange(Unknown Source)
    at com.sun.javafx.collections.VetoableObservableList.setAll(Unknown Source)
    at com.sun.javafx.collections.ObservableListWrapper.setAll(Unknown Source)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(Unknown Source)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(Unknown Source)
    at com.sun.javafx.scene.control.skin.SkinBase$4.changed(Unknown Source)
    at javafx.beans.value.WeakChangeListener.changed(Unknown Source)
    at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(Unknown Source)
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown Source)
    at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(Unknown Source)
    at javafx.beans.property.StringPropertyBase.markInvalid(Unknown Source)
    at javafx.beans.property.StringPropertyBase.set(Unknown Source)
    at javafx.beans.property.StringPropertyBase.set(Unknown Source)
    at javafx.beans.property.StringProperty.setValue(Unknown Source)
    at javafx.scene.control.Labeled.setText(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2388)
    at groovy.lang.ExpandoMetaClass.setProperty(ExpandoMetaClass.java:1170)
    at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3312)
    at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:183)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:480)
    at com.temenos.att.view.ATTReplay$_playAction_closure2.doCall(ATTReplay.groovy:169)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at com.temenos.att.view.ATTReplay$_playAction_closure2.doCall(ATTReplay.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
    at groovy.lang.Closure.call(Closure.java:410)
    at groovy.lang.Closure.call(Closure.java:404)
    at groovy.lang.Closure.run(Closure.java:488)
    at java.lang.Thread.run(Thread.java:722)


Please kindly help on this.
     

Jim Clarke

unread,
Jan 4, 2012, 8:16:57 AM1/4/12
to Naveedur Rahman, us...@groovy.codehaus.org
At what point do you set a Stage's visible attribute to 'true'?

jim


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Naveed

unread,
Jan 4, 2012, 8:42:29 AM1/4/12
to us...@groovy.codehaus.org
I set Stage visible attribute to true in Stage construtor itself.

sg.stage(title: "Login Demo", show: true, onHidden:{System.exit(0)}) {
...
}

--
View this message in context: http://groovy.329449.n5.nabble.com/GroovyFx-Thread-tp5119325p5119613.html
Sent from the groovy - user mailing list archive at Nabble.com.

Jim Clarke

unread,
Jan 4, 2012, 9:19:47 AM1/4/12
to us...@groovy.codehaus.org
Not seeing all your code it is a little difficult to see what is happening,
but I will take a shot.

When defer is called it actually pushes a task on to a queue, then the JavaFX runtime
pops the queue and runs that task on the JavaFX thread.
Since "showPageContents" is pushed first, it must run to completion before "showProgress"
is popped and then run.

I am not sure what exactly you are doing in both methods, but
what I would do is, assuming the Stage is already visible:

1) Create one of the progress controls, (ProgressBar or ProgressIndicator)
assign it to the scene and set its visible attribute to true.
2) Do whatever is needed in showPageContents
3) Set the progress control visible to false, then remove it from the scene.

The Progress control runs its own timing thread while visible, and periodically updates the scene
with updates.

jim

Reply all
Reply to author
Forward
0 new messages