1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.appstatus.demo.batch;
17
18 import java.io.IOException;
19 import java.util.concurrent.ExecutorService;
20 import java.util.concurrent.Executors;
21
22 import javax.servlet.ServletException;
23 import javax.servlet.ServletOutputStream;
24 import javax.servlet.http.HttpServlet;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.springframework.web.context.support.WebApplicationContextUtils;
29
30
31
32
33
34
35
36 public class LaunchClassicBatchSampleServlet extends HttpServlet {
37
38 private static final String ENCODING = "UTF-8";
39
40
41
42
43 private static final long serialVersionUID = -8830877354343317996L;
44
45
46
47
48
49
50
51
52 @Override
53 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
54 throws ServletException, IOException {
55
56
57 ExecutorService executorService = Executors.newCachedThreadPool();
58
59 BatchSample batch = (BatchSample) WebApplicationContextUtils
60 .getRequiredWebApplicationContext(getServletContext()).getBean(
61 "batch");
62 executorService.execute(batch);
63
64 BatchSample2 batch2 = (BatchSample2) WebApplicationContextUtils
65 .getRequiredWebApplicationContext(getServletContext()).getBean(
66 "batch2");
67 executorService.execute(batch2);
68
69 ServletOutputStream os = resp.getOutputStream();
70
71 os.write("<html><head".getBytes(ENCODING));
72 os.write("<body>".getBytes(ENCODING));
73 os.write("<h1>Ok</h1>".getBytes(ENCODING));
74 os.write("</body></html>".getBytes(ENCODING));
75 }
76 }