Multi-threaded, object loss when sharing Httpserveltrequest objects

Source: Internet
Author: User

Problem background: A more complex query function in Web projects, need to call a lot of the underlying interface, take up more time, if the normal user thread, is an interface of the call, the whole time will be many, so the use of multi-threaded query. For each underlying is a one-thread query, and after the query is completed, the summary results are returned.

Problem Description: The thread of the program-initiated query interface (sub-thread below) is sometimes httpservletrequest when calling a shared object. Sometimes normal does not error. This is very strange, because HttpServletRequest is in the user thread when the servlet container is automatically initialized, the various properties are ready, and there is no way to provide delete properties.

Problem conjecture: When the child thread calls the HttpServletRequest property is lost, it is definitely where to delete, the user program is not called, that is, the servlet container was deleted. So it is possible that the user thread has been executed and returned to the front end, and Sevlet that the servlet-related data used by the thread is useless, so the Servlet object is automatically destroyed. The child thread has not finished yet, and the servlet is still in use, indicating that the child thread execution timeout has not been completed and the main thread is no longer waiting.

Check conjecture: The child thread execution time is set very long to ensure that subsequent tasks in the child threads have sufficient time to execute. After repeated testing, there is no longer the problem of ServletRequest object loss, speculation is correct.

Program FIX: No longer use httpserveltrequest as a shared object before each thread. Customizes a thread-safe common object, encapsulates similar client-related data into the object, and then uses it for data passing between the various method threads.

Multi-threaded, object loss when sharing Httpserveltrequest objects

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.