Tomcat - Servlet init() called twice upon startup

后端 未结 4 880
刺人心
刺人心 2021-01-19 23:59

I have an issue with a standalone Tomcat server (not linked with Apache).

When Tomcat starts up, the init() method of the servlet is getting called twice, i.e., two

相关标签:
4条回答
  • 2021-01-20 00:24

    Tomcat is autodeploying anything in webapps, and also deploying according to server.xml. Just remove your webapp from webapps to avoid double loading.

    0 讨论(0)
  • 2021-01-20 00:26

    If the init() method fails, it may be called again on a subsequent get. Did you check the catalina.out file to make sure that the init() call is not being aborted for some reason?

    0 讨论(0)
  • 2021-01-20 00:27

    I would set a breakpoint in the init() method and then look at the stack to see where the calls are coming from.

    0 讨论(0)
  • 2021-01-20 00:34

    There is a bug in your code. Your singleton is not thread-safe. That getInstance() method should be synchronised. Otherwise you are liable to construct multiple instances.

    0 讨论(0)
提交回复
热议问题