クラスで使用InheritableThreadLocal
しています。Servlet
その子スレッドから利用できるようにします。InheritableThreadLocal
スレッドプールエグゼキュータで悪を使用していますか? . サーブレット スレッド プールなど。
私の質問。
InheritableThreadLocals
1)サーブレットでの使用を避ける必要があるのはなぜですか?
2) でこのメモリ リークが発生する可能性はありInheritableThreadLocal
ますか?
3) ? に代わるものはありInheritableThreadLocal
ますか。
4) スレッドが再利用され、格納されている値threadlocal
がクリアされない場合はどうなりますか?
私のリアルタイムシナリオ
public class UserAccessFilter implements javax.servlet.Filter {
static final InheritableThreadLocal<String> currentRequestURI = new InheritableThreadLocal<String>();
public void doFilter(ServletRequest req, ServletResponse resp , FilterChain fc) throws IOException, ServletException{
String uri = request.getRequestURI();
fc.doFilter(request, response);
}
}
public class MailServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String mailCount = req.getParameter("mailCount");
if(mailCount != null && !"".equals(mailCount) && mailCount.matches("[0-9]+")){
MailThread mailThread = new MailThread("xxx@gmail.com", generateToAddress(Integer.parseInt(mailCount))); //NO I18N
Thread t = new Thread(mailThread);
t.start();
}
resp.getWriter().println("Mail Servlet.............."); //NO I18N
}
}
class MailThread implements Runnable{
private String from;
private String to;
public MailThread(String from , String to){
this.from = from;
this.to = to;
}
@Override
public void run() {
sendMail();
}
public void sendMail(){
//I want this uri from child threads. I can't pass this value to this constructor.
String uri = currentRequestURI.get();
//Do Mail Operations
}
}
フィルター --> サーブレット A --> 子スレッド ---> メール スレッド (ここでは、フィルターに設定された値を取得しています)。