Current Position:Home > Problem with Threads and "plase wait..."-Window

Problem with Threads and "plase wait..."-Window

Update:10-11Source: network consolidation
Hi everyone,
I have a problem that I'm not able to solve in any way... I have a time-consuming task (a file decryption) which I execute in a separate thread; I've used the SwingWorker class, like suggested by sun-tutorial, and it works right. The problem is that I have to wait that the decryption have finished before continuing with program-execution. Therefore I would like to display a "please wait"-window while the task runs. I've tryed all the possible ways I know but the problem is always the same: the waitWindow is displayed empty, the bounds are painted but the contents no; it's only painted when the decrypt-task has finished. Please help me, I have no more resources....
decrypt-file code:
public class DecryptFile {
  private String cryptedFileNameAndPath;
  private ByteArrayInputStream resultStream = null;
  // need for progress
  private int lengthOfTask;
  private int current = -1;
  private String statMessage;
  public DecryptFile(String encZipFileNameAndPath) {
    cryptedFileNameAndPath = encZipFileNameAndPath;
    //Compute length of task...
    // 0 for indeterminate
    lengthOfTask = 0;
  public ByteArrayInputStream getDecryptedInputStream() {
    return this.resultStream;
   * Called from ProgressBarDemo to start the task.
  public void go() {
    current = -1;
    final SwingWorker worker = new SwingWorker() {
      public Object construct() {
        return new ActualTask();
   * Called from ProgressBarDemo to find out how much work needs
   * to be done.
  public int getLengthOfTask() {
    return lengthOfTask;
   * Called from ProgressBarDemo to find out how much has been done.
  public int getCurrent() {
    return current;
  public void stop() {
    current = lengthOfTask;
   * Called from ProgressBarDemo to find out if the task has completed.
  public boolean done() {
    if (current >= lengthOfTask)
      return true;
      return false;
  public String getMessage() {
    return statMessage;
   * The actual long running task.  This runs in a SwingWorker thread.
  class ActualTask {
    ActualTask () {
      current = -1;
      statMessage = "";
      resultStream = AIUtil.getInputStreamFromEncZip(cryptedFileNameAndPath); //here the decryption happens
      current = 0;
      statMessage = "";
  }The code that calls decryption and displays waitWindow
      final WaitSplash wS = new WaitSplash("Please wait...");
      final DecryptFile cryptedTemplate = new DecryptFile (this.templateFile);
      while (! cryptedTemplate.done()) {
        try {
        } catch (Exception e) { }
      this.templateInputStream = cryptedTemplate.getDecryptedInputStream();
      wS.close();Thanks, thanks, thanks in advance!

The Best Answer

Maybe you can try setting the priority of the long-running thread to be lower? so that the UI will be more responsive...