/[projects]/dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Lookup.java
ViewVC logotype

Diff of /dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Lookup.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2241 by torben, Wed Dec 10 09:50:33 2014 UTC revision 2260 by torben, Mon Feb 9 14:00:53 2015 UTC
# Line 2  package dk.daoas.fulddaekning; Line 2  package dk.daoas.fulddaekning;
2    
3  import java.util.Map;  import java.util.Map;
4  import java.util.Queue;  import java.util.Queue;
5  import java.util.concurrent.ConcurrentHashMap;  import java.util.concurrent.*;
6  import java.util.logging.Level;  import java.util.logging.Level;
7  import java.util.logging.Logger;  import java.util.logging.Logger;
8    
# Line 22  public class Lookup { Line 22  public class Lookup {
22                    
23          Map<Integer, LookupWorker> workers = new ConcurrentHashMap<Integer, LookupWorker>();          Map<Integer, LookupWorker> workers = new ConcurrentHashMap<Integer, LookupWorker>();
24    
25                    ThreadPoolExecutor threadPool;  
26    
27                                    
28                    
29          public Lookup(String postnr, Database db) {          public Lookup(String postnr, Database db, ThreadPoolExecutor threadPool) {
30                  this.postnr = postnr;                  this.postnr = postnr;
31                  this.db = db;                  this.db = db;
32                    this.threadPool = threadPool;
33          }          }
34                    
35    
# Line 71  public class Lookup { Line 72  public class Lookup {
72                                                                                                                                                                                                                                    
73                          for (int i =0; i < LookupMain.max_workers; i++) {                          for (int i =0; i < LookupMain.max_workers; i++) {
74                                  LookupWorker worker = new LookupWorker(i, this);                                  LookupWorker worker = new LookupWorker(i, this);
75                                  Thread t = new Thread(worker);                                  threadPool.submit(worker);
                                 t.start();  
                                   
                                 workers.put(i, worker);  
76                          }                          }
77                                                    
78                          while (workers.size() > 0) {                          while (threadPool.getActiveCount() > 0 || threadPool.getQueue().isEmpty() == false) {
79                                  Thread.sleep(10);//wait for worker threads                                  Thread.sleep(10);//wait for worker threads
80                          }                          }
81                                                    
# Line 102  public class Lookup { Line 100  public class Lookup {
100                  logger.info("Done! elapsed=" + (now-start1) + "/" +  (now-start2) + "  postnr=" + postnr);                  logger.info("Done! elapsed=" + (now-start1) + "/" +  (now-start2) + "  postnr=" + postnr);
101          }          }
102                    
         public void shutdownWorker(int workerid) {  
                 //logger.info("Shutting down worker: " + workerid);  
                 LookupWorker key = workers.remove(workerid);  
                   
                 if (key == null) {  
                         System.out.println("Error removing worker from set " + workerid);  
                         System.exit(0);  
                 }  
         }  
103                    
104          // Getters and setters          // Getters and setters
105                                    

Legend:
Removed from v.2241  
changed lines
  Added in v.2260

  ViewVC Help
Powered by ViewVC 1.1.20