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