How to execute long running tasks in NetBeans platform…

Written by Tom Hublek on January 30th, 2007

We work on J2EE project based on NetBeans platform and we solve typical tasks. My first problem was execution of long running tasks.

Here is a solution:

  private void jbExecuteActionPerformed(java.awt.event.ActionEvent evt) {                                                    // start thread    RequestProcessor.getDefault().post(new Runnable() {       public void run() {          ProgressHandle progress =                 ProgressHandleFactory.createHandle("Loading data...");                            progress.start(10);                            try {            for (int i = 1; i < 10; i++) {              try {                 Thread.sleep(2000);              } catch (InterruptedException ex) { }               progress.progress(i);            }          } finally {            progress.finish();          }       }    });  }          

The trick is in RequestProcessor.getDefault().post(new Runnable(){...}).

Inside new Runnable(){...} you may optionally use NetBeans Progress API

  • Share/Bookmark
 

Leave a Comment