--- dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Lookup.java 2014/12/10 09:50:33 2241 +++ dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Lookup.java 2015/02/09 13:21:39 2259 @@ -2,7 +2,7 @@ import java.util.Map; import java.util.Queue; -import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -22,13 +22,14 @@ Map workers = new ConcurrentHashMap(); - + ThreadPoolExecutor threadPool; - public Lookup(String postnr, Database db) { + public Lookup(String postnr, Database db, ThreadPoolExecutor threadPool) { this.postnr = postnr; this.db = db; + this.threadPool = threadPool; } @@ -71,13 +72,13 @@ for (int i =0; i < LookupMain.max_workers; i++) { LookupWorker worker = new LookupWorker(i, this); - Thread t = new Thread(worker); + /*Thread t = new Thread(worker); t.start(); - workers.put(i, worker); + workers.put(i, worker);*/ } - while (workers.size() > 0) { + while (threadPool.getActiveCount() > 0) { Thread.sleep(10);//wait for worker threads } @@ -102,15 +103,6 @@ logger.info("Done! elapsed=" + (now-start1) + "/" + (now-start2) + " postnr=" + postnr); } - 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); - } - } // Getters and setters