/[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 2258 by torben, Wed Dec 10 09:50:33 2014 UTC revision 2259 by torben, Mon Feb 9 13:21:39 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);                                  /*Thread t = new Thread(worker);
76                                  t.start();                                  t.start();
77                                                                    
78                                  workers.put(i, worker);                                  workers.put(i, worker);*/
79                          }                          }
80                                                    
81                          while (workers.size() > 0) {                          while (threadPool.getActiveCount() > 0) {
82                                  Thread.sleep(10);//wait for worker threads                                  Thread.sleep(10);//wait for worker threads
83                          }                          }
84                                                    
# Line 102  public class Lookup { Line 103  public class Lookup {
103                  logger.info("Done! elapsed=" + (now-start1) + "/" +  (now-start2) + "  postnr=" + postnr);                  logger.info("Done! elapsed=" + (now-start1) + "/" +  (now-start2) + "  postnr=" + postnr);
104          }          }
105                    
         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);  
                 }  
         }  
106                    
107          // Getters and setters          // Getters and setters
108                                    

Legend:
Removed from v.2258  
changed lines
  Added in v.2259

  ViewVC Help
Powered by ViewVC 1.1.20