How to execute long running tasks in NetBeans platform…

Written By: Tomáš Hubálek - Jan• 30•07

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

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Your email address will not be published. Required fields are marked *