1 |
package dk.daoas.daoadresseservice.db; |
package dk.daoas.daoadresseservice.db; |
2 |
|
|
3 |
import java.sql.SQLException; |
import java.sql.SQLException; |
4 |
import java.util.concurrent.Executor; |
import java.util.concurrent.ExecutorService; |
5 |
import java.util.concurrent.Executors; |
import java.util.concurrent.Executors; |
6 |
|
|
7 |
import dk.daoas.daoadresseservice.beans.SearchResult; |
import dk.daoas.daoadresseservice.beans.SearchResult; |
8 |
|
|
9 |
public class LogPersistance { |
public class LogPersistance { |
10 |
|
|
11 |
Executor threadPool = Executors.newFixedThreadPool(1); |
ExecutorService threadPool = Executors.newFixedThreadPool(1); |
12 |
|
|
13 |
static class LogPersistanceWorker implements Runnable { |
static class LogPersistanceWorker implements Runnable { |
14 |
String brugerid; |
String brugerid; |
28 |
try { |
try { |
29 |
DatabaseLayer.saveRequestLog(brugerid,postnr,adresse,result); |
DatabaseLayer.saveRequestLog(brugerid,postnr,adresse,result); |
30 |
} catch (SQLException e) { |
} catch (SQLException e) { |
31 |
System.out.println("Error saving log entry " + e.getMessage() ); |
System.out.println("Error saving log entry " + e.getMessage() + ". Postnr=" + postnr + ". Adresse=" + adresse); |
32 |
} |
} |
33 |
} |
} |
34 |
} |
} |
36 |
public void saveRequestLog(String brugerid, String postnr, String adresse, SearchResult result) { |
public void saveRequestLog(String brugerid, String postnr, String adresse, SearchResult result) { |
37 |
threadPool.execute( new LogPersistanceWorker(brugerid,postnr,adresse,result) ); |
threadPool.execute( new LogPersistanceWorker(brugerid,postnr,adresse,result) ); |
38 |
} |
} |
39 |
|
|
40 |
|
|
41 |
|
public void shutdown() { |
42 |
|
threadPool.shutdown(); |
43 |
|
} |
44 |
} |
} |