Threading Question for java.awt.Robot.mouseRelease(x,y)

66 views
Skip to first unread message

Andrew Hughes

unread,
Jan 19, 2010, 8:18:16 PM1/19/10
to jfxtr...@googlegroups.com
Hi Guys,

I'm lost here. We're invoking a java.awt.Robot.mouseRelease(x,y) with very poor response times. Blocking perhaps... do any of the FX or Swing guru's know if I should be running this in a FX.deferAction() or a java.awt.EventQueue.invokeLater()?

Many Thanks.


Stephen Chin

unread,
Jan 19, 2010, 10:56:09 PM1/19/10
to jfxtr...@googlegroups.com
JavaFX threading is a black art...  but since you asked.  :-)

deferAction won't help...  it just runs it on the EDT later, so you will block at some time in the future rather than immediately, but still block.  invokeLater is equivalent (and actually the desktop profile implementation of deferAction).

The safe way is to create a javafx.async.Task and write your robot code in Java.  This way the JavaFX code is all executed on the EDT, and you can run your robot code in the background on a non-blocking thread.

The potentially-not-safe way is to use our jfxtras XWorker (used to be JFXWorker) or my new favorite, XEDT.  They both allow you to run code in the background that is written in JavaFX, but make sure that you do not interact with the UI or use language features that are inherently not thread-safe (like sequences).

I hope this helps.

Cheers,
--Steve

Andrew Hughes wrote:


--
You received this message because you are subscribed to the Google Groups "JFXtras Developers" group.
To post to this group, send email to jfxtr...@googlegroups.com.
To unsubscribe from this group, send email to jfxtras-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jfxtras-dev?hl=en.

Andrew Hughes

unread,
Jan 19, 2010, 11:58:39 PM1/19/10
to jfxtr...@googlegroups.com
Hi Steve,

Very helpful! I'll stick to a background (java) Runnable (thread) invoking the robot. I would assume that the incoming event interrupts and invokes the GUI (EDT) in a thread safe fashion (fingers crossed anyway).

THANKS!!!!

Stephen Chin

unread,
Jan 20, 2010, 8:53:19 AM1/20/10
to jfxtr...@googlegroups.com
I should have mentioned that as well...  calling JavaFX from a background thread is not safe, because it will invoke it off EDT.  Make sure you wrap your JavaFX callback code in a deferAction call.

Cheers,
--Steve
--
--Steve
blog: http://steveonjava.com/

Jim Clarke

unread,
Jan 20, 2010, 10:15:41 AM1/20/10
to jfxtr...@googlegroups.com
From java code you should call com.sun.javafx.runtime.Entry.deferAction(Runnable function) or use the javafx.async package.
The EDT call does not exist on all platforms and in the future may not be supported even on the Desktop.

jim
Jim Clarke
Principal Technologist
OEM Software Sales



Pedro Duque Vieira

unread,
Jan 20, 2010, 10:21:16 AM1/20/10
to jfxtr...@googlegroups.com

Hi,

 

Jim, the deferAction won’t exist in the future? Why?

 

Thanks =)

Jim Clarke

unread,
Jan 20, 2010, 10:24:54 AM1/20/10
to jfxtr...@googlegroups.com
That is not what I said.   deferAction() will continue to exist, however, java.awt.EventQueue may not be available.


jim

Pedro Duque Vieira

unread,
Jan 20, 2010, 10:30:32 AM1/20/10
to jfxtr...@googlegroups.com

Ok, thanks Jim.

Andrew Hughes

unread,
Jan 20, 2010, 5:41:24 PM1/20/10
to jfxtr...@googlegroups.com
This is unclear (to me anyway). I want to call java.awt.Robot.mouseRelease(), but should this be run on or off the EDT? Since awt currently implements the FX runtime ui, does this mean it's really on the EDT and I should deferAction()? Or is this something special in AWT that is thread safe and can be invoked from any thread? I'm not sure where the FX/Java boundaries are :)

I hope I am making at least a tiny bit of sense :)
Reply all
Reply to author
Forward
0 new messages