public void run() { boolean bDOWNLOADOK = false; while (!this.bisinterrupted) { try { synchronized (JFCMainClient.dlm) { // debugoutput("going to sleep."); JFCMainClient.dlm.wait( 1000); // check for new URLs (if they got pasted faster than threads removing them) // debugoutput("woke up ".concat(this.getClass().getName())); this.bisinterrupted = JFCMainClient .getbQuitrequested(); // if quit was pressed while this threads works it would not // get the InterruptedException and therefore prevent // application shutdown // debugoutput("URLs remain in list: // ".concat(Integer.toString(JFCMainClient.dlm.size()))); // running in CLI mode? if (JFCMainClient.frame == null) { if (JFCMainClient.dlm.size() == 0) { debugoutput(this.getMyName().concat(" ran out of work.")); if (YTDownloadThread.iThreadcount == 0) { // this is the last DownloadThread so shutdown Application as well debugoutput("all DownloadThreads ended. shuting down ytd2."); JFCMainClient.shutdownAppl(); } else { // this is not the last DownloadThread so shutdown this thread only this.bisinterrupted = true; debugoutput("end this thread."); throw new NullPointerException("end this thread."); } } } this.sURL = JFCMainClient.getfirstURLFromList(); output( (JFCMainClient.isgerman() ? "versuche herunterzuladen: " : "try to download: ") .concat(this.sURL)); JFCMainClient.removeURLFromList(this.sURL); } // sync dlm if (JFCMainClient.frame != null) // only if we have a GUI window insert "downloading" text JFCMainClient.addYTURLToList(JFCMainClient.szDLSTATE.concat(this.sURL)); this.bNODOWNLOAD = JFCMainClient .getbNODOWNLOAD(); // copy ndl-state because this thread should end with a complete // file (and report so) even if someone switches to no-download // before this thread is finished // download one webresource and show result bDOWNLOADOK = downloadone(this.sURL); this.iRecursionCount = -1; if (bDOWNLOADOK && !this.bNODOWNLOAD) output( (JFCMainClient.isgerman() ? "fertig heruntergeladen: " : "download complete: ") .concat("\"") .concat(this.getTitle()) .concat("\"") .concat(" to ") .concat(this.getFileName())); else output( (JFCMainClient.isgerman() ? "Nicht heruntergeladen: " : "not downloaded: ") .concat("\"") .concat(this.getTitle()) .concat("\"")); // not downloaded does not mean it was erroneous // running in CLI mode? if (JFCMainClient.frame == null) JFCMainClient.removeURLFromList(this.sURL); else JFCMainClient.removeURLFromList(JFCMainClient.szDLSTATE.concat(this.sURL)); // notify download complete eventDispatcher.threadNumberChanged(JFCMainClient.dlm.size()); } catch (InterruptedException e) { this.bisinterrupted = true; } catch (NullPointerException npe) { // debugoutput("npe - nothing to download?"); } catch (Exception e) { e.printStackTrace(); } // try } // while debugoutput("thread ended: ".concat(this.getMyName())); YTDownloadThread.iThreadcount--; } // run()