Tomcat hot deployment, Web project thread not terminated

Source: Internet
Author: User

In a recent project, when deploying Web Engineering with Jenkins Hot, it was found that statically held threads in the project (storing the Scheduledexecutorservice timer task in a static map) resulted in a database access transaction closing exception, as follows: Org.springframework.transaction.CannotCreateTransactionException:Could not open JPA Entitymanager for transaction; Nested exception is java.lang.IllegalStateException:EntityManagerFactory is closed

Seeing this problem, the class that has been considered to be manipulating the database does not have a transaction declaration, so add @transactional to the class, but it does not take effect. And the program does not periodically call the Runnable class in the project, and then report the above error. Obviously there is only one thread, but there are multiple threads running, guess should be before the hot deployment, the timing thread stored in the static resource is not purged. Reboot Tomcat and find no error. Therefore, the location is Tomcat hot deployment, static resources for release.

Conjecture: The legacy thread is not released, is still running, the operation of the database, the exception that created the transaction failed, should be after the Web Engineering hot deployment, Spring's transaction management is invalidated, unable to create the transaction.

Workaround :

(1) Use annotations in Java EE5 @predestroy

(2) Use Disposablebean in spring or configure Destroy-method. (class implements the Disposablebean interface to implement resource deallocation in the Destroy () method)

Reference:

Deep understanding of Spring transaction Principles

A detailed description of spring transaction management

Thorough mastery of the use of @transactional in Spring

Jenkins Tomcat hot deployment, Task thread recurring boot workaround

Annotations @postconstruct and @predestroy and examples

[email protected] and @predestroy instances

Spring Bean Initializingbean and Disposablebean instances

Tomcat hot deployment, Web project thread not terminated

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.