Mercurial > hg > Database > jungle-network
comparison src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java @ 155:83e99eba6ec1
async thread comtext in showmessage servlet
author | tatsuki |
---|---|
date | Wed, 09 Jul 2014 19:44:47 +0900 |
parents | 29734d7d6521 |
children | 89999029c543 |
comparison
equal
deleted
inserted
replaced
154:a6bf0369f0a6 | 155:83e99eba6ec1 |
---|---|
1 package app.bbs; | 1 package app.bbs; |
2 | 2 |
3 import java.io.PrintWriter; | 3 import java.io.PrintWriter; |
4 | 4 |
5 import javax.servlet.AsyncContext; | |
5 import javax.servlet.http.HttpServlet; | 6 import javax.servlet.http.HttpServlet; |
6 import javax.servlet.http.HttpServletRequest; | 7 import javax.servlet.http.HttpServletRequest; |
7 import javax.servlet.http.HttpServletResponse; | 8 import javax.servlet.http.HttpServletResponse; |
9 | |
10 import org.eclipse.jetty.util.thread.ThreadPool; | |
8 | 11 |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; | 12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; |
10 | 13 |
11 public class ShowMessageWithTimeStampServlet extends HttpServlet | 14 public class ShowMessageWithTimeStampServlet extends HttpServlet |
12 { | 15 { |
15 */ | 18 */ |
16 private static final long serialVersionUID = 1L; | 19 private static final long serialVersionUID = 1L; |
17 private final NetworkBulletinBoard bbs; | 20 private final NetworkBulletinBoard bbs; |
18 private final String createBoardMessagePath; | 21 private final String createBoardMessagePath; |
19 private final String editMessagePath; | 22 private final String editMessagePath; |
23 private ThreadPool threadPool; | |
20 | 24 |
21 private static final String PARAM_BOARD_NAME = "bname"; | 25 private static final String PARAM_BOARD_NAME = "bname"; |
22 | 26 |
23 public ShowMessageWithTimeStampServlet(NetworkBulletinBoard _bbs,String _createBoardMessagePath, String _editMessagePath) | 27 public ShowMessageWithTimeStampServlet(NetworkBulletinBoard _bbs,String _createBoardMessagePath, String _editMessagePath, ThreadPool thp) |
24 { | 28 { |
25 bbs = _bbs; | 29 bbs = _bbs; |
26 createBoardMessagePath = _createBoardMessagePath; | 30 createBoardMessagePath = _createBoardMessagePath; |
27 editMessagePath = _editMessagePath; | 31 editMessagePath = _editMessagePath; |
32 threadPool = thp; | |
28 } | 33 } |
29 | 34 |
30 public void doGet(HttpServletRequest _req,HttpServletResponse _res) | 35 public void doGet(HttpServletRequest _req,HttpServletResponse _res) |
31 { | 36 { |
32 String bname = _req.getParameter(PARAM_BOARD_NAME); | 37 final AsyncContext asc = _req.startAsync(); |
33 | 38 final String bname = _req.getParameter(PARAM_BOARD_NAME); |
34 try{ | 39 Runnable printBoardThread = new Runnable() { |
35 printBoard(bname,_res.getWriter()); | 40 @Override |
36 }catch(Exception _e){ | 41 public void run() { |
37 _res.setStatus(500); | 42 try{ |
38 } | 43 printBoard(bname,_res.getWriter()); |
39 | 44 }catch(Exception _e){ |
45 _res.setStatus(500); | |
46 } | |
47 asc.complete(); | |
48 } | |
49 }; | |
50 threadPool.execute(printBoardThread); | |
40 } | 51 } |
41 | 52 |
42 private void printBoard(String _bname,PrintWriter _pw) throws Exception | 53 private void printBoard(String _bname,PrintWriter _pw) throws Exception |
43 { | 54 { |
44 _pw.write("<html><body>\n"); | 55 _pw.write("<html><body>\n"); |