title: Call a function after a Thread is completed
body: <p>i'm writing a Sftp-client program using Jsch. I am using JProgressBars to display the Progress of Uploads and Downloads. My GUI contains Buttons according to the files in my Working Directory. When i delete a file i updated my gui to give the user a feedback:</p>
  
  <pre><code>void update() {
      panel.removeAll();
      addToPanel(ls(channelsftp, sftpWorkingDir));
      validate();
  }
  </code></pre>
  
  <p>This is using my ls-function to return all Files in the current workingDir. addToPanel will process the lsEntries to output Buttons on the panel. This works great for deleting files. However, i want the same update-function to be called after an upload is completed. Since upload is giving me graphical feedback in the form of a JProgressBar its functionality was moved to a thread:</p>
  
  <pre><code>final JFileChooser uploadChooser = new JFileChooser();
      ulo.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
              int returnVal = uploadChooser.showOpenDialog(Navigator.this);
              if(returnVal == JFileChooser.APPROVE_OPTION) {
                  String pathToUpload = uploadChooser.getSelectedFile().getAbsolutePath();
                  Runnable uploadIt = new UploadUtil(pathToUpload, chacha);
                  new Thread(uploadIt).start();
              }   
          }
      });
  </code></pre>
  
  <p>So after the user clicks on OK in this JFileChooser the upload starts. Here is UploadUtil:</p>
  
  <pre><code>public class UploadUtil implements Runnable{
  
      String paTU;
      ChannelSftp csftp;
  
      public UploadUtil(String pathToUl, ChannelSftp chaSftp) {
          paTU = pathToUl;
          csftp = chaSftp;
      }
  
      @Override
      public void run() {
          try {
              csftp.put(paTU, LoginAndFunctions.sftpWorkingDir, new SystemOutProgressMonitor());
          } catch (SftpException e) {
              Error errorUploading = new Error(e.toString()+"\nUploadpipe closed unexpectedly");
              errorUploading.setVisible(true);
          }
      }
  }
  </code></pre>
  
  <p>SystemOutProgressMonitor is a class that processes datatransfer in Jsch.
  I tried using Thread.join() and CountDownLatch. Both prevented my JProgressBar from updating. Is there a different solution for it?</p>