10 |
|
|
11 |
ExecutorService threadPool = Executors.newFixedThreadPool(1); |
ExecutorService threadPool = Executors.newFixedThreadPool(1); |
12 |
|
|
13 |
static class LogPersistanceWorker implements Runnable { |
private static class LogPersistanceWorker implements Runnable { |
14 |
|
|
15 |
|
DatabaseLayer db; |
16 |
String brugerid; |
String brugerid; |
17 |
String postnr; |
String postnr; |
18 |
String adresse; |
String adresse; |
19 |
SearchResult result; |
SearchResult result; |
20 |
|
|
21 |
public LogPersistanceWorker(String brugerid, String postnr, String adresse, SearchResult result) { |
public LogPersistanceWorker(DatabaseLayer db, String brugerid, String postnr, String adresse, SearchResult result) { |
22 |
|
this.db = db; |
23 |
this.brugerid = brugerid; |
this.brugerid = brugerid; |
24 |
this.postnr = postnr; |
this.postnr = postnr; |
25 |
this.adresse = adresse; |
this.adresse = adresse; |
29 |
@Override |
@Override |
30 |
public void run() { |
public void run() { |
31 |
try { |
try { |
32 |
DatabaseLayer.saveRequestLog(brugerid,postnr,adresse,result); |
db.saveRequestLog(brugerid,postnr,adresse,result); |
33 |
} catch (SQLException e) { |
} catch (SQLException e) { |
34 |
System.out.println("Error saving log entry " + e.getMessage() ); |
System.out.println("Error saving log entry " + e.getMessage() + ". Postnr=" + postnr + ". Adresse=" + adresse); |
35 |
} |
} |
36 |
} |
} |
37 |
} |
} |
38 |
|
|
39 |
public void saveRequestLog(String brugerid, String postnr, String adresse, SearchResult result) { |
public void saveRequestLog(DatabaseLayer db, String brugerid, String postnr, String adresse, SearchResult result) { |
40 |
threadPool.execute( new LogPersistanceWorker(brugerid,postnr,adresse,result) ); |
threadPool.execute( new LogPersistanceWorker(db, brugerid, postnr, adresse, result) ); |
41 |
} |
} |
42 |
|
|
43 |
|
|
45 |
threadPool.shutdown(); |
threadPool.shutdown(); |
46 |
} |
} |
47 |
} |
} |
48 |
|
|