1 |
torben |
2274 |
package dk.daoas.daoadresseservice;
|
2 |
|
|
|
3 |
|
|
import java.sql.SQLException;
|
4 |
|
|
|
5 |
|
|
import javax.servlet.ServletContext;
|
6 |
|
|
import javax.servlet.ServletContextEvent;
|
7 |
|
|
import javax.servlet.ServletContextListener;
|
8 |
|
|
import javax.servlet.annotation.WebListener;
|
9 |
|
|
|
10 |
|
|
/**
|
11 |
|
|
* Application Lifecycle Listener implementation class ContextListener
|
12 |
|
|
*
|
13 |
|
|
*/
|
14 |
|
|
@WebListener
|
15 |
|
|
public class ContextListener implements ServletContextListener {
|
16 |
torben |
2281 |
|
17 |
|
|
public static class DataLoader implements Runnable {
|
18 |
|
|
ServletContext ctxt;
|
19 |
|
|
public DataLoader(ServletContext ctxt) {
|
20 |
|
|
this.ctxt = ctxt;
|
21 |
|
|
}
|
22 |
|
|
|
23 |
torben |
2274 |
|
24 |
torben |
2281 |
@Override
|
25 |
|
|
public void run() {
|
26 |
|
|
|
27 |
|
|
AdressSearch search = new AdressSearch();
|
28 |
|
|
try {
|
29 |
|
|
search.buildSearchStructures();
|
30 |
|
|
ctxt.setAttribute("search", search);
|
31 |
|
|
} catch (SQLException e) {
|
32 |
|
|
System.out.println("Error loading data: " + e.getMessage());
|
33 |
|
|
}
|
34 |
|
|
}
|
35 |
|
|
|
36 |
torben |
2274 |
|
37 |
torben |
2281 |
}
|
38 |
|
|
|
39 |
|
|
|
40 |
torben |
2274 |
public ContextListener() {
|
41 |
|
|
// TODO Auto-generated constructor stub
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
public void contextDestroyed(ServletContextEvent ctxtEvt) {
|
45 |
|
|
// TODO Auto-generated method stub
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
public void contextInitialized(ServletContextEvent ctxtEvt) {
|
49 |
|
|
System.out.println("Starting DAO Context");
|
50 |
|
|
|
51 |
|
|
ServletContext ctxt = ctxtEvt.getServletContext();
|
52 |
|
|
|
53 |
torben |
2284 |
Thread t = new Thread( new DataLoader(ctxt), "SearchDataLoader");
|
54 |
torben |
2281 |
t.start();
|
55 |
torben |
2274 |
|
56 |
|
|
System.out.println("DAO Context done");
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
}
|