Tomcat hot deployment, the Web project thread is not terminated, tomcatweb

Source: Internet
Author: User

Tomcat hot deployment, the Web project thread is not terminated, tomcatweb

In a recent project, when you use jenkins to deploy a web project, you will find the static threads in the project (storing ScheduledExecutorService scheduled tasks in static Map ), an exception occurs when the database access transaction is closed from time to time, as shown in the following code: org. springframework. transaction. cannotCreateTransactionException: cocould not open JPA EntityManager for transaction; nested exception is java. lang. illegalStateException: EntityManagerFactory is closed

Seeing this problem, I always think that the class that operates the database has no transaction declaration, So adding @ Transactional to the class does not take effect. In addition, the program calls the Runnable class in the project from time to time, and then reports the preceding error. It is clear that there is only one thread, but multiple threads run. It is assumed that the scheduled threads stored in static resources were not cleared during hot deployment. Restart Tomcat and no error will be reported. Therefore, it is positioned as Tomcat hot deployment, and static resources are released.

Conjecture: The Legacy thread has not been released and is still running. In this case, an exception occurs when a transaction fails to be created when the web project is hot deployed. The Spring transaction management has expired, A transaction cannot be created.

Solution:

(1) Use the annotation @ PreDestroy in Java EE5

(2) Use DisposableBean in Spring or configure destroy-method. (Class implements the DisposableBean interface and releases resources in the destroy () method)

Refer:

Deep understanding of Spring transaction principles

Spring transaction management

Thoroughly understand the use of @ transactional in Spring

Solution for hot deployment of jenkins tomcat and repeated startup of task threads

Annotation @ PostConstruct and @ PreDestroy details and examples

Spring @ PostConstruct and @ PreDestroy instances

Spring Bean InitializingBean and DisposableBean instances

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.