How to execute a long running task from an action without blocking the GUI?

The easy way if you might need to run a long task when some action is involved:

@ActionRegistration(asynchronous = true)
public void actionPerformed(ActionEvent ev) {
    if (isLongTaskRequired) {
        // maybe run a ProgressHandler
    EventQueue.invokeLater(new Runnable() {
        @Override public void run() {
            // do domething with the gui

This way you don't even need to care about threading yourself, GUI will be updated as long as the task is finished.

Taken from (Oct 2013)

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo