1   package eu.fbk.knowledgestore.populator.naf;
2   
3   import java.io.IOException;
4   
5   public class finalizeThread implements Runnable {
6   
7       @Override
8       public void run() {
9           while (true) {
10              if (allThreadsDied()&&nafPopulator.JobFinished) {
11                  try {
12                      footer();
13                      nafPopulator.nullObjects();
14                      return;
15                  } catch (IOException e) {
16                      e.printStackTrace();
17                  }
18              }
19             
20          }
21          
22      }
23  
24      private boolean allThreadsDied() {
25          boolean notFinished = true;
26          for (Thread tmp : nafPopulator.threads) {
27              if (tmp.isAlive())
28                  notFinished = false;
29              //System.err.println("Threads(" + tmp.getId() + ") - alive:" + tmp.isAlive());
30          }
31  
32         // System.err.println("Threads alive check: " + notFinished);
33          return notFinished;
34      }
35  
36      void footer() throws IOException {
37  
38      	if(nafPopulator.out!=null){
39          nafPopulator.out.append("Global stats:\n").append(nafPopulator.globalStats.getStats());
40          nafPopulator.out.flush();       
41      	}else{
42      		System.err.println("Error: report file has been closed!");
43      		System.err.println("The report is:");
44      		System.err.println("Global stats:\n"+nafPopulator.globalStats.getStats());
45      		 
46      	}
47      }
48    /*  
49      void  footer() throws IOException{
50          if(!called&&(nafPopulator.JobFinished&&queue.isEmpty())){
51              called=true;
52          nafPopulator.out.append("Global stats:\n").append(nafPopulator.globalStats.getStats());
53          nafPopulator.out.flush();
54          
55          if (!nafPopulator.printToFile&&(nafPopulator.JobFinished||queue.isEmpty())) {
56              nafPopulator.closeConnection();
57          }else{
58              nafPopulator.mentionFile.flush();
59              nafPopulator.mentionFile.close();
60          }
61         // out.append("Global stats:\n").append(globalStats.getStats());
62          //out.flush();
63          nafPopulator.out.close();
64          nafPopulator.nullObjects();
65          }
66      }*/
67  
68  }