/** * This method represents the application code that we'd like to run on a separate thread. It * simulates slowly computing a value, in this case just a string 'All Done'. It updates the * progress bar every half second to remind the user that we're still busy. */ Object doWork() { try { if (Thread.interrupted()) { throw new InterruptedException(); } while (!this.state.terminator.isTerminated(this.state.optimizer.getPopulation())) { if (Thread.interrupted()) { throw new InterruptedException(); } this.state.optimizer.optimize(); } System.gc(); } catch (InterruptedException e) { updateStatus("Interrupted", 0); return "Interrupted"; } updateStatus("All Done", 0); return "All Done"; }