/[projects]/dao/DaoAdresseService/src/dk/daoas/daoadresseservice/DataLoader.java
ViewVC logotype

Contents of /dao/DaoAdresseService/src/dk/daoas/daoadresseservice/DataLoader.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2337 - (show annotations) (download)
Mon Feb 23 12:30:41 2015 UTC (9 years, 2 months ago) by torben
File size: 1426 byte(s)
First version of admin page and data reload
1 package dk.daoas.daoadresseservice;
2
3 import java.sql.SQLException;
4
5 import javax.servlet.ServletContext;
6
7 public class DataLoader {
8
9 boolean isRunning = false;
10
11 ServletContext ctxt;
12 public DataLoader(ServletContext ctxt) {
13 this.ctxt = ctxt;
14 }
15
16 public void doLoad() {
17 synchronized(this) {
18 if (isRunning == false) {
19 isRunning = true;
20
21 Thread t = new Thread( new DataLoadWorker(this), "SearchDataLoader");
22 t.start();
23 }
24 }
25 }
26
27 public boolean isRunning() {
28 synchronized(this) {
29 return isRunning;
30 }
31 }
32
33 protected void setRunningFalse() {
34 synchronized(this) {
35 isRunning = false;
36 }
37 }
38
39
40
41
42 public static class DataLoadWorker implements Runnable {
43 DataLoader loader;
44 public DataLoadWorker(DataLoader ld) {
45 this.loader = ld;
46 }
47
48
49 @Override
50 public void run() {
51
52
53 try {
54 AdressSearch search = new AdressSearch();
55 search.buildSearchStructures();
56
57 AdressSearch oldSearch = (AdressSearch) loader.ctxt.getAttribute("search");
58 loader.ctxt.setAttribute("search", search);
59
60 if (oldSearch != null) {
61 oldSearch.clear();
62 }
63
64 } catch (SQLException e) {
65 System.out.println("Error loading data: " + e.getMessage());
66 } finally {
67 loader.setRunningFalse();
68 }
69
70 }
71
72
73 }
74
75 }

  ViewVC Help
Powered by ViewVC 1.1.20