Esempio n. 1
0
    public boolean readNext() {
      ExecutionReq executionReq = null;
      this.cntExecutions++;
      try {
        synchronized (executionReqQueue) {
          if (executionReqQueue.size() > 0) {
            executionReq = executionReqQueue.get(0);
            executionReqQueue.remove(0);
          }
        }
        if (executionReq != null) {
          executionReq.log(this.threadNumber, this.cntExecutions, "started");

          executionReq.startedAt = System.currentTimeMillis();
          Downloader downloader =
              new Downloader(executionReq, this.threadNumber, this.cntExecutions);
          Parser parser = new Parser(executionReq, this.threadNumber, this.cntExecutions);

          downloader.start();
          parser.start();

          parser.join();
          executionReq.endedAt = System.currentTimeMillis();
          executionReq.log(
              this.threadNumber,
              this.cntExecutions,
              "completed OK in "
                  + ((int) ((executionReq.endedAt - executionReq.startedAt) / 1000))
                  + " seconds");
          executionReq.logCompleted(this.threadNumber, this.cntExecutions);
        }
      } catch (Exception ex) {
        if (executionReq != null) {
          try {
            executionReq.log(this.threadNumber, this.cntExecutions, "an error occurred:" + ex);
            if (executionReq.outFile != null && executionReq.outFile.exists())
              executionReq.outFile.delete();
          } catch (Exception e2) {
          }
        } else {
          ex.printStackTrace();
        }
        executionReq = null;
      }
      return executionReq != null;
    }
Esempio n. 2
0
 public static void main(String[] args) {
   Parser p = new Parser();
   p.start();
 }