0

Fire and Forget function

asked 2011-03-31 15:32:13 +0800

zknewbie1 gravatar image zknewbie1
370 4

Hi, I'd like to implement a Fire and Forget functionality, for example a <button id='myBtn' onClick='myBtn_onClick()' /> . The myBtn_onClick() event with call another method that runs some reports and then email the report to the user in the background. The key thing is the onClick event should not wait for this background method. Is there a way to do it? Your insight is greatly appreciated...

sample zul:
========
<button id='myBtn' onClick='myBtn_onClick()' />

sample java:
=========
public void myBtn_onClick() throws Exceptions {
this.runReports();//should not wait for the method to complete, should go to the next line and display the Messagebox
// and finish the onClick event
Messagebox.show("Reports are being run and you'll get email notification shortly....");
}//end method

private void runReports() {
//Run some reports and email users once done
}//end method

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-04-01 04:17:13 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

updated 2011-04-01 04:21:41 +0800

Please read:

http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/UI%20Patterns/Long%20Operations

The simple approach (if you don't need to inform the user when the work is finished)... call runReports as dedicated Thread:

public void myBtn_onClick() throws Exceptions { 
  new Thread(new Runnable() {
    public void run() {
        runReports();
    }
  }).start();
  Messagebox.show("Reports are being run and you'll get email notification shortly...."); 

Cheers, Maik

link publish delete flag offensive edit

answered 2011-04-01 09:36:06 +0800

zknewbie1 gravatar image zknewbie1
370 4

Thanks a lot Maik...

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-03-31 15:32:13 +0800

Seen: 159 times

Last updated: Apr 01 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More