我有一个在tomcat服务器启动时调用的Servlet。
的web.xml
<servlet>
<servlet-name>PollingServlet</servlet-name>
<servlet-class>com.bsli.servlet.PollingServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PollingServlet</servlet-name>
<url-pattern>/PollingServlet</url-pattern>
</servlet-mapping>
PollingServlet.java
public class PollingServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
Logger logger = Logger.getLogger(PollingServlet.class);
public void init(){
try {
super.init();
logger.debug("PollingServlet :: Initializing ...");
try {
CMConnectionPool.destroyPool();
CMBConnection connection1 = CMConnectionPool.getConnection();
logger.debug("CM Connection 1 achieved");
CMBConnection connection2 = CMConnectionPool.getConnection();
logger.debug("CM Connection 2 achieved");
CMBConnection connection3 = CMConnectionPool.getConnection();
logger.debug("CM Connection 3 achieved");
CMBConnection connection4 = CMConnectionPool.getConnection();
logger.debug("CM Connection 4 achieved");
CMBConnection connection5 = CMConnectionPool.getConnection();
logger.debug("CM Connection 5 achieved");
CMConnectionPool.freeConnection(connection1);
CMConnectionPool.freeConnection(connection2);
CMConnectionPool.freeConnection(connection3);
CMConnectionPool.freeConnection(connection4);
CMConnectionPool.freeConnection(connection5);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread pollThread = new Thread(new PollingFolder());
pollThread.start();
logger.debug("PollingServlet thread Started ..");
} catch (ServletException e) {
e.printStackTrace();
}
}
}
当我使用上面的类来创建如上所述的ConnectionPool时,应用程序不会继续进行。我在日志文件中获得了上述日志,但之后没有任何反应。 当我评论1行时,它正常工作。