Asynchronous Tasks"

From Documentation
Line 7: Line 7:
 
Here is the pseudo code:
 
Here is the pseudo code:
 
<source lang="java">
 
<source lang="java">
// in a separate thread, other than a servlet thread
+
    // these codes below are in a separate thread, other than a servlet thread
// run a long task
+
    // run a long task
// then push the result on UI
+
    // then push the result on UI
Executions.schedule(desktop,
+
    Executions.schedule(desktop,
    new EventListener() {
+
        new EventListener() {
        public void onEvent(Event event) {
+
            public void onEvent(Event event) {
            updateUI(); //whatever you like
+
                updateUI(); //whatever you like
        }
+
            }
    }, event);
+
        }, event);
 
</source>
 
</source>
  

Revision as of 03:57, 28 June 2019


Asynchronous Tasks


If the task of updating UI can be represented as a method, the push can be done easily. All you need to do is

  1. Implement the UI updates in an event listener (implementing EventListener or SerializableEventListener).
  2. Then, schedule it for executed asynchronously by the use of Executions.schedule(Desktop, EventListener, Event).

Here is the pseudo code:

    // these codes below are in a separate thread, other than a servlet thread
    // run a long task
    // then push the result on UI
    Executions.schedule(desktop,
        new EventListener() {
            public void onEvent(Event event) {
                updateUI(); //whatever you like
            }
        }, event);

You could manipulate UI whatever you want in EventListener.onEvent(Event). It is no different from any other event listener.

Notice that Executions.schedule(Desktop, EventListener, Event) can be called anywhere, including another event listener or a working thread. In other words, you don't have to fork a working thread to use this feature.

Notice that, since there is at most one thread to access the UI of a given desktop, the event listener's performance must be good. Otherwise, it will block other event listeners from execution. Thus, if you have a long operation to do, you could use event queue's asynchronous event listener, or implement it as a synchronous task and handle lengthy operation outside of the activation block.

Version History

Last Update : 2019/06/28


Version Date Content
5.0.6 November 2010 This feature was introduced. With 5.0.5 or prior, you have to use Event Queues or Synchronous Tasks.



Last Update : 2019/06/28

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.