当前位置:   article > 正文

java springmvc ServletContextListener监听_springmvc 监听servletcontext

springmvc 监听servletcontext
  1. package com.esafenet.ta.da.reoortriskrule.listener;
  2. import javax.servlet.ServletContextEvent;
  3. import javax.servlet.ServletContextListener;
  4. public class ReportRiskRule implements ServletContextListener{
  5. private ReportThread reportThread = null;
  6. /**
  7. * 上下文销毁时监听执行方法
  8. */
  9. @Override
  10. public void contextDestroyed(ServletContextEvent arg0) {
  11. System.out.println("哎呦 关了");
  12. destroyThread();
  13. }
  14. /**
  15. * 上下文启动时监听执行方法
  16. */
  17. @Override
  18. public void contextInitialized(ServletContextEvent arg0) {
  19. System.out.println("哎呦启动了");
  20. startThreat();
  21. }
  22. /**
  23. * 启动线程
  24. */
  25. private void startThreat() {
  26. if(reportThread==null){
  27. reportThread = new ReportThread();
  28. reportThread.start();
  29. }
  30. }
  31. /**
  32. * 销毁线程
  33. */
  34. private void destroyThread() {
  35. if(reportThread != null && reportThread.isInterrupted()){
  36. reportThread.interrupt();
  37. }
  38. }
  39. /**
  40. * 轮训的线程执行下级给上级上报风险数据
  41. * @author Administrator
  42. *
  43. */
  44. private class ReportThread extends Thread{
  45. @Override
  46. public void run() {
  47. while(true){
  48. try {
  49. System.out.println("我是轮训一直输出");
  50. Thread.sleep(3000);
  51. } catch (InterruptedException e) {
  52. // TODO Auto-generated catch block
  53. e.printStackTrace();
  54. }
  55. }
  56. }
  57. }
  58. // public static void main(String[] args) {
  59. // if(reportThread==null){
  60. // reportThread = new ReportThread();
  61. // reportThread.start();
  62. // }
  63. // }
  64. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/799302?site
推荐阅读
相关标签
  

闽ICP备14008679号