SystemInitServlet.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.persagy.framework.servlet;
  2. import javax.servlet.ServletContext;
  3. import javax.servlet.ServletException;
  4. import javax.servlet.http.HttpServlet;
  5. import org.apache.log4j.Logger;
  6. import org.springframework.web.context.WebApplicationContext;
  7. import org.springframework.web.context.support.WebApplicationContextUtils;
  8. import com.persagy.core.mvc.service.CoreService;
  9. import com.persagy.framework.util.ConfigUtil;
  10. import com.persagy.framework.util.PropertyUtil;
  11. import com.persagy.functions.weather.service.DayHisRecordService;
  12. import com.persagy.functions.weather.service.DayStaticService;
  13. import com.persagy.functions.weather.service.DependApiStaticService;
  14. import com.persagy.functions.weather.service.DisasterWarningService;
  15. import com.persagy.functions.weather.service.HourRecordService;
  16. import com.persagy.functions.weather.thread.DayDataRecordThread;
  17. import com.persagy.functions.weather.thread.DayStaticThread;
  18. import com.persagy.functions.weather.thread.DependAPIStaticThread;
  19. import com.persagy.functions.weather.thread.DisasterWarningThread;
  20. import com.persagy.functions.weather.thread.HourDataRecordThread;
  21. import com.persagy.functions.weather.thread.Min5LongHuThread;
  22. import com.persagy.functions.weather.thread.RequestIpStatisticThread;
  23. public class SystemInitServlet extends HttpServlet {
  24. private static final long serialVersionUID = 8077103762776343464L;
  25. private static final Logger log = Logger.getLogger(SystemInitServlet.class);
  26. @Override
  27. public void init() throws ServletException {
  28. log.info("system init start......");
  29. ServletContext sc = this.getServletContext();
  30. WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(sc);
  31. CoreService coreService = (CoreService) context.getBean("coreService");
  32. DisasterWarningService disasterService = (DisasterWarningService) context.getBean("disasterWarningService");
  33. HourRecordService hourRecordService = (HourRecordService) context.getBean("hourRecordService");
  34. DayHisRecordService dayHisRecordService = (DayHisRecordService) context.getBean("dayHisRecordService");
  35. DayStaticService dayStaticService = (DayStaticService) context.getBean("dayStaticService");
  36. DependApiStaticService dependApiStaticService = (DependApiStaticService) context.getBean("dependApiStaticService");
  37. log.info("config info init start...");
  38. try {
  39. ConfigUtil.cache_refresh_all();
  40. } catch (Exception e) {
  41. log.error("load config info error");
  42. System.exit(1);
  43. }
  44. String threadRun = PropertyUtil.getSystemProperty("thread.model");
  45. if("true".equals(threadRun)) {
  46. log.info("business thread objects start...");
  47. new Thread(new Min5LongHuThread(coreService)).start();
  48. new Thread(new HourDataRecordThread(hourRecordService)).start();
  49. new Thread(new DisasterWarningThread(disasterService)).start();
  50. new Thread(new DayDataRecordThread(dayHisRecordService)).start();
  51. new Thread(new DayStaticThread(dayStaticService)).start();
  52. new Thread(new DependAPIStaticThread(dependApiStaticService, "Thread")).start();
  53. }else {
  54. RequestIpStatisticThread rist = new RequestIpStatisticThread(coreService);
  55. rist.init();
  56. new Thread(rist).start();
  57. new Thread(new DependAPIStaticThread(dependApiStaticService, "Business")).start();
  58. }
  59. log.info("system init end.");
  60. }
  61. }