Updating the GUI from a background Thread: Platform.Runlater() Vs Tasks

Hi Everyone,
Hereby I would like to ask if anyone can enlighten me on the best practice for concurency with JAVAFX2. More precisely, if one has to update a Gui from a background Thread what should be the appropriate approach.
I further explain my though:
I have window with a text box in it and i receive some message on my network on the background, hence i want to update the scrolling textbox of my window with the incoming message. In that scenario what is the best appraoch.
1- Shall i implement my my message receiver as thread in which i would then use a platform.RunLater() ?
2- Or shall i use a Task ? In that case, which public property of the task shall take the message that i receive ? Are property of the task only those already defined, or any public property defined in subclass can be used to be binded in the graphical thread ?
In general i would like to understand, what is the logic behind each method ?
My understanding here, is that task property are only meant to update the gui with respect to the status of the task. However updating the Gui about information of change that have occured on the data model, requires Platform.RunLater to be used.
Edited by: 987669 on Feb 12, 2013 12:12 PM

Shall i implement my my message receiver as thread in which i would then use a platform.RunLater() ?Yes.
Or shall i use a Task ?No.
what is the logic behind each method?A general rule of thumb:
a) If the operation is initiated by the client (e.g. fetch data from a server), use a Task for a one-off process (or a Service for a repeated process):
- the extra facilities of a Task such as easier implementation of thread safety, work done and message properties, etc. are usually needed in this case.
b) If the operation is initiated by the server (e.g. push data to the client), use Platform.runLater:
- spin up a standard thread to listen for data (your network communication library will probably do this anyway) and to communicate results back to your UI.
- likely you don't need the additional overhead and facilities of a Task in this case.
Tasks and Platform.runLater are not mutually exclusive. For example if you want to update your GUI based on a partial result from an in-process task, then you can create the task and in the Task's call method, use a Platform.runLater to update the GUI as the task is executing. That's kind of a more advanced use-case and is documented in the Task documentation as "A Task Which Returns Partial Results" http://docs.oracle.com/javafx/2/api/javafx/concurrent/Task.html

Similar Messages

  • Update listview from a background thread

    my thread listens to the mails coming to outlook. i have a list in javafx stage which displays the inbox of my outlook. when i get a new mail it should appear in my listview also how to do that. pls help.

    Updating a control that is currently visible must always be done from the JavaFX event thread. So, updating a control directly from a background thread will not work.
    Hiowever, there is a function in the Platform class, Platform.runLater(), that allows you to submit a Runnable that will be executed on the JavaFX event thread as soon as possible. From this Runnable you can update your controls.
    Platform.runLater(new Runnable() {
      public void run() {
        // do your updates here (no big calculatiions though as that would block the FX thread resulting in an unresponsive UI).
    });

  • I had a repair done on my MacBook Pro and had to have a new hard drive installed. The Apple Auth Repair Shop then updated the OS from 10.6.8 to 10.7.5. Now my iPhoto v 9.2.3 will not open and it sounds like it will not work with this OS. Can you plea

    I had a repair done on my MacBook Pro and had to have a new hard drive installed. The Apple Auth Repair Shop then updated the OS from 10.6.8 to 10.7.5. Now my iPhoto v 9.2.3 will not open and it sounds like it will not work with this OS. Can you please advise?

    You may need many other updates to retain compatibility with Lion. I suggest you reinstall Snow Leopard. Unfortunately, you will need to erase the drive first. Be sure to backup your data if you haven't done so already.
    Clean Install of Snow Leopard
    Be sure to make a backup first because the following procedure will erase
    the drive and everything on it.
         1. Boot the computer using the Snow Leopard Installer Disc or the Disc 1 that came
             with your computer.  Insert the disc into the optical drive and restart the computer.
             After the chime press and hold down the  "C" key.  Release the key when you see
             a small spinning gear appear below the dark gray Apple logo.
         2. After the installer loads select your language and click on the Continue
             button. When the menu bar appears select Disk Utility from the Utilities menu.
             After DU loads select the hard drive entry from the left side list (mfgr.'s ID and drive
             size.)  Click on the Partition tab in the DU main window.  Set the number of
             partitions to one (1) from the Partitions drop down menu, click on Options button
             and select GUID, click on OK, then set the format type to MacOS Extended
             (Journaled, if supported), then click on the Apply button.
         3. When the formatting has completed quit DU and return to the installer.  Proceed
             with the OS X installation and follow the directions included with the installer.
         4. When the installation has completed your computer will Restart into the Setup
             Assistant. After you finish Setup Assistant will complete the installation after which
             you will be running a fresh install of OS X.  You can now begin the update process
             by opening Software Update and installing all recommended updates to bring your
             installation current.
    Download and install Mac OS X 10.6.8 Update Combo v1.1.

  • I can't update the iphone4, from an insertion iOS4.3.1 on an insertion iOS 4.3.3 - itunes gives out me an error 3259. What to me to do? How to me to update the iphone?

    I can't update the iphone4, from an insertion iOS4.3.1 on an insertion iOS 4.3.3 - itunes gives out me an error 3259. What to me to do? How to me to update the iphone?

    Temporarily disable your firewall and ALL of your antivirus/antispyware software and try again.

  • Extraction time while updating the data from update rule

    Hello Friends,
    Can you please tell me that why it is taking more time while updating the data from update rule to data target.
    I believe that it is taking 40% of total extraction time.
    Is there any specific reason for it?
    Prompt reply will be appreciated.
    Regards,

    hi,
    check if you have complex transformation in that update rules, like calculation, read from other tables, etc.
    take a look 'bw loading performance and analysis' doc
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/1955ba90-0201-0010-d3aa-8b2a4ef6bbb2
    and bi performance tuning knowledge center
    Business Intelligence Performance Tuning [original link is broken]
    there e-learning for bw performance
    hope this helps.

  • I have a 2nd generation iPod touch.  I have not updated the software from version 2.2.1.  When I connect to iTunes to update to 4.2, I keep getting an error message.  Has anyone else had this issue and figured out a way to fix it?

    I have a 2nd generation iPod touch.  I have not updated the software from version 2.2.1.  When I connect to iTunes to update to 4.2, I keep getting an error message.  Has anyone else had this issue and figured out a way to fix it?

    Error -1
    Attempt to restore your iOS device two more times. If the issue is still unresolved, the device may need service.
    The "device may need service" means a hardware problem. In that case make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar
    Also see:
    -1 error
    -1 error too

  • HT4623 i m using iphone 3gs & i m updating the OS from 4.1 to 6.1 ,,it is showing the message that ur iphone cannot be activated because the activation server is not temporarily unavailable

    i m using iphone 3gs & i m updating the OS from 4.1 to 6.1 ,,it is showing the message that ur iphone cannot be activated because the activation server is not temporarily unavailable

    Contact your Carrier...
    Also see this discussion.
    https://discussions.apple.com/message/21189708

  • Impossible to update the softwares from the top CC menu. First the menu does'nt show the software on my computers and after a while of seaching, the icon disapear from the menu and no uptade. Can someone tell me why. Thank you

    Impossible to update the softwares from the top CC menu. First the menu does'nt show the software on my computers and after a while of seaching, the icon disapear from the menu and no uptade. Can someone tell me why. Thank you

    This is an open forum with a mix of other users and Adobe staff, not Adobe support... you need Adobe support
    Adobe contact information - http://helpx.adobe.com/contact.html may help
    -Select your product and what you need help with
    -Click on the blue box "Still need help? Contact us"

  • Can we update the data from SSRS report to any database ?

    Hi Team,
    Greetings !!!!
    Can we update the data from SSRS report to any database ?
    Thanks,
    Anand Gavle.

    Nope SSRS doesnt have write back options. Its just a reporting tool
    However one thing you can do is to link a webpage from SSRS report and do the changes through it
    SSRS has the ability to navigate to web page through which you can capture any data inputs from users and save it to your db.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • HT4623 my 2nd. generation ipod will not update the software from 2.2 to 4

    my 2nd. geration ipod will not update the software from 2.2 to 4 or 6.

    Are you sure you have a 2G? A 1G can only go to 2.1 via iTunes but a 1G can go as high as 3.1.3 that you get here:
    Purchasing iOS 3.1 Software Update for iPod touch (1st generation)
    Identifying iPod models
    To If you do have a 2G that can go to 4.2.1 by:
    iTunes: Backing up, updating, and restoring iOS software
    For 4.2.1 you need iTunes version 10.X and that requires OSX 105.8 or later.
    If you have 10.4.11 you can only go to iOS 4.1 since that OSX can on go to iTunes 9.X

  • Updating the result from Labveiw to Test stand!

    Hello, I
    have a quick question; i am using Labview 8.5 & Test Stand. I am
    develeoping Test Scripts using Labview for the design & using them in
    Teststand as PASS/FAIL tests. My question is when i run the tests in teststand
    its showing that the tests what i have written in labview has been passed but
    when i remove the connection to UUT & run the same its showing that tests
    are passed. Actually at this time it should show that the tests are failed
    since the connection to UUT is not present. But on the lab view window its showing
    the proper result(that the is failed due to to bad connection) but on the test
    stand window side its showing erroneous results i.e. tests are passed(i.e. the
    result is not being updated from lab view to test stand window). What should I  do  to
    update the result from lab veiw to testand . I have this problem from couple of
    days.
    Any help
    would be appreciated.
    Thanks.

    Hi basha,
    Looking at your Sequence File and the Pass / Fail Step in MainSequence.
    Although you have three connections on your VI FT_Open_Device_By_Sreial_Number.vi (one input, two outputs),
    within your step, you haven't connected them to any TestStand variables.
    I have attached the FileGlobals.Handle to the Handle output of your VI as an example.
    You need to do something similar for Device Serial Number and FT_Status.
    I am not sure where this top level vi comes in, are you hoping to replace FT_Open_Device_By_Sreial_Number.vi with this top level vi.
    If you are then you need to connect on input and output to its connector pane. I would suggest the boolean result is one of the ouptut
    Which you connect to Step.Result.Pass/Fail
    Regards
    Ray
    Message Edited by Ray Farmer on 03-10-2008 10:04 PM
    Regards
    Ray Farmer
    Attachments:
    vi.PNG ‏25 KB
    Specify Pass_Fail.PNG ‏24 KB
    top level.PNG ‏6 KB

  • How do you monitor a background thread and update the GUI

    Hello,
    I have a thread which makes its output available on PipedInputStreams. I should like to have other threads monitor the input streams and update a JTextArea embedded in a JScrollPane using the append() method.
    According to the Swing tutorial, the JTextArea must be updated on the Event Dispatch Thread. When I use SwingUtilities.invokeLater () to run my monitor threads, the component is not redrawn until the thread exits, so you don't see the progression. If I add a paint () method, the output is choppy and the scrollbar doesn't appear until the thread exits.
    Ironically, if I create and start new threads instead of using invokeLater(), I get the desired result.
    What is the correct architecture to accomplish my goal without violating Swing rules?
    Thanks,
    Brad
    Code follows:
    import java.lang.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SystemCommand implements Runnable
         private String[] command;
         private PipedOutputStream pipeout;
         private PipedOutputStream pipeerr;
         public SystemCommand ( String[] cmd )
              command = cmd;
              pipeout = null;
              pipeerr = null;
         public void run ()
              exec ();
         public void exec ()
              // --- Local class to redirect the process input stream to a piped output stream
              class OutputMonitor implements Runnable
                   InputStream is;
                   PipedOutputStream pout;
                   public OutputMonitor ( InputStream i, PipedOutputStream p )
                        is = i;
                        pout = p;
                   public void run ()
                        try
                             int inputChar;
                             for ( ;; )
                                  inputChar = is.read();
                                  if ( inputChar == -1 ) { break; }
                                  if ( pout == null )
                                       System.out.write ( inputChar );
                                  else
                                       pout.write ( inputChar );
                             if ( pout != null )
                                  pout.flush ();
                                  pout.close ();
                             else
                                  System.out.flush();
                        catch ( Exception e ) { e.printStackTrace (); }     
              try
                   Runtime r = Runtime.getRuntime ();
                   Process p = r.exec ( command );
                   OutputMonitor out = new OutputMonitor ( p.getInputStream (), pipeout );
                   OutputMonitor err = new OutputMonitor ( p.getErrorStream (), pipeerr );
                   Thread t1 = new Thread ( out );
                   Thread t2 = new Thread ( err );
                   t1.start ();
                   t2.start ();
                   //p.waitFor ();
              catch ( Exception e ) { e.printStackTrace (); }
         public PipedInputStream getInputStream () throws IOException
              pipeout = new PipedOutputStream ();
              return new PipedInputStream ( pipeout );
         public PipedInputStream getErrorStream () throws IOException
              pipeerr = new PipedOutputStream ();
              return new PipedInputStream ( pipeerr );
         public void execInThread ()
              Thread t = new Thread ( this );
              t.start ();
         public static JPanel getContentPane ( JTextArea ta )
              JPanel p = new JPanel ( new BorderLayout () );
              JPanel bottom = new JPanel ( new FlowLayout () );
              JButton button = new JButton ( "Exit" );
              button.addActionListener ( new ActionListener ( )
                                       public void actionPerformed ( ActionEvent e )
                                            System.exit ( 0 );
              bottom.add ( button );
              p.add ( new JScrollPane ( ta ), BorderLayout.CENTER );
              p.add ( bottom, BorderLayout.SOUTH );
              p.setPreferredSize ( new Dimension ( 640,480 ) );
              return p;
         public static void main ( String[] argv )
              // --- Local class to run on the event dispatch thread to update the Swing GUI
              class GuiUpdate implements Runnable
                   private PipedInputStream pin;
                   private PipedInputStream perr;
                   private JTextArea outputArea;
                   GuiUpdate ( JTextArea textArea, PipedInputStream in )
                        pin = in;
                        outputArea = textArea;
                   public void run ()
                        try
                             // --- Reads whole file before displaying...takes too long
                             //outputArea.read ( new InputStreamReader ( pin ), null );
                             BufferedReader r = new BufferedReader ( new InputStreamReader ( pin ) );
                             String line;
                             for ( ;; )
                                  line = r.readLine ();
                                  if ( line == null ) { break; }
                                  outputArea.append ( line + "\n" );
                                  // outputArea.paint ( outputArea.getGraphics());
                        catch ( Exception e ) { e.printStackTrace (); }
              // --- Create and realize the GUI
              JFrame f = new JFrame ( "Output Capture" );
              f.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
              JTextArea textOutput = new JTextArea ();
              f.getContentPane().add ( getContentPane ( textOutput ) );
              f.pack();
              f.show ();
              // --- Start the command and capture the output in the scrollable text area
              try
                   // --- Create the command and setup the pipes
                   SystemCommand s = new SystemCommand ( argv );
                   PipedInputStream stdout_pipe = s.getInputStream ();
                   PipedInputStream stderr_pipe = s.getErrorStream ();
                   // --- Launch
                   s.execInThread ( );
                   //s.exec ();
                   // --- Watch the results
                   SwingUtilities.invokeLater ( new GuiUpdate ( textOutput, stdout_pipe ) );
                   SwingUtilities.invokeLater ( new GuiUpdate ( textOutput, stderr_pipe ) );
                   //Thread t1 = new Thread ( new GuiUpdate ( textOutput, stdout_pipe ) );
                   //Thread t2 = new Thread ( new GuiUpdate ( textOutput, stderr_pipe ) );
                   //t1.start ();
                   //t2.start ();
              catch ( Exception e ) { e.printStackTrace (); }
              

    Thanks for pointing out the SwingWorker class. I didn't use it directly, but the documentation gave me some ideas that helped.
    Instead of using invokeLater on the long-running pipe-reader object, I run it on a normal thread and let it consume the output from the background thread that is running the system command. Inside the reader thread I create a tiny Runnable object for each line that is read from the pipe, and queue that object with invokeLater (), then yield() the reader thread.
    Seems like a lot of runnable objects, but it works ok.

  • Unable to update the values from store procedure

    hi ,
    I have simple table with 3 columns. id, name , sal. am updating the salary based on names. 
    alter PROCEDURE p1(@names varchar(100))
    AS
    BEGIN
    declare @empData varchar(200)
    set @empData= '''' + replace(@names,',',''',''')+''''
    print @empData
    update tmp set sal =10 where name in ( @empData )
    END
    GO
    if I execute same query (update tmp set sal =10 where name in ( @empData )) outside with printed @empData data it is working fine.
    why the same is not working with SP ?
    any ideas...

    You need to split the list into a temporary table or table valued variable:
    alter PROCEDURE p1(@names varchar(100))
    AS
    BEGIN
    declare @empTable table ([name] varchar(100));
    declare @p int = 1;
    declare @len int = len(@names);
    declare @nextP int = charindex(',', @name, @p) ;
    set @nextP = case when @nextP = 0 then @len else @nextP end;
    while @p < @len
    begin
    insert into @empTable
    values (substring(@names, @p, @nextP-1));
    set @p = @nextP + 1;
    Set @nextP int = charindex(',', @name, @p) ;
    set @nextP = case when @nextP = 0 then @len else @nextP
    end
    update tmp
    set sal =10
    where name in (Select [name] from @empTable );
    END
    GO
    Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

  • CLD: Do you have to create the GUI from scratch?

    I'm a little confused, because the ATM Machine example instructions seem to imply you're supposed to create the front panel from scratch. It also gave specifications on the Account.txt file.
    However, some posts on this board have led me to believe that a GUI (and even data files) are provided for you ahead of time.
    For people who have actually taken the exam: do I need to practice throwing the GUI together when I run through the practice exams, or should I be copying over the front panel from the solution?
    Thanks.
    http://linkd.in/mikele

    In your exam packet, a USB stick will be provided. The USB stick will have the following:
    A folder hierarchy consisting of two folders: SubVIs and Controls. You must use the folder hierarchy as provided and save your work in these folders.
    The main VI with a fully developed front panel and the associated typedefs saved in the Controls folder. You must utilize the front panel as given. Note: You will have fill in the tips/description for the Controls, the VI documentation and develop a simple icon.
    A data file (.csv or ini) file needed for the application
    We are currently in the process of updating the sample exams to reflect this change. The updated samples will be available in the first week of July.
    Thanks
    Zaki Chasmawala | Certification Development Group Manager | Training & Certification | National Instruments | [email protected]

  • Main VI is not updating the data from subVI

    Dear all,
    I
    have a Vi A using the data front a subVi B. When I run it, I see the
    data is updating in the subVI, but not the main Vi and the Front Panel.
    The subVi has three output channels and the main Vi tries to display
    those three channel data on the Front Panel.
    Could somebody tell me how I can solve the problem?
    Thanks a lot.
    Roy
    Solved!
    Go to Solution.

    You could probably use Control Refnums but as Dennis mentioned, be sure to explain the use case to us.
    How Can I Update the Changes Made to a Control/Indicator from a SubVI on the main VI?
    Message Edited by Adnan Z on 06-02-2009 02:48 PM
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

Maybe you are looking for

  • ADF 10.1.3.3  Blocking attribute commandbutton does not work

    I can set the blocking="true" for my commandbutton in my jspx and it works fine on my local and on a dev server. (working as expected with the hourglass). In a different dev environment (the one we use to preview to our users) when the user clicks on

  • Is there a way to save data to just one view in Flex Mobile applications?

    I am having trouble handling data between views in a Flex Mobile application that I am writing. I know how to pass data from one view to another, but I was wondering if there is a way to save that data to a view, then get more data from another view

  • Itunes has stopped working during optimizing

    I am running iTunes 10.4.1.10 and syncing to an iPhone 4.  Syncing used to work, but all of a sudden after backing up and copting apps during Optimizing 1 of 5, I get "Itunes has stopped working"  then need to click which ends iTunes.  Ideas?

  • A Bug in iOS7 Using Siri with in Car Bluetooth

    I have a near new Hyundai SanteFe with built in bluetooth.  Under iOs6 it worked fine when listening to CD, Radio or Music from the iPhone. Now, if I use Siri when using Radio or CD it still works fine.  However if I am listening to Music app on the

  • Set Default Values in Listbox with Dialog Programming

    Hi all, I am stuck with a problem i.e  I am working with Dialog Programming Screen where i have to set default values in some n numbers of Listbox which i have created on Screen. This default value is needed to be fetched from database table. I am us