Multithreaded business processing logic

1. Springboot project. There is a
new Thread (new Runnable () {

in the post request API.
//

})
means that the front end will open a thread for business logic processing for each request interface. This is because the business processing in the thread is very time-consuming (basically about half an hour). Because the experience is not allowed to be stuck consistently, the thread is opened for business processing, and the interface returns an ID. The front end can view it by identifying the percentage of thread execution in the business in another interface, and the execution phase in the thread business logic is updated in the database. Empty another interface for query.
2. The business in the thread does not have a statement similar to
while (true) {}
, because it takes time to execute the business and queries processed in the business, and the execution completion thread ends.
3, the current problem is that if the front-end concurrent requests (30 times), and then there will be no response in the request interface, restart normally
4, I generally know that the memory in the thread should not be released, but I do not know how to optimize
5, the main question is how to handle this kind of time-consuming requests relatively well; let the thread memory processing should be how to handle and release.

Mar.16,2021

use thread pooling. In addition, to determine whether the task is logically duplicated, ignore subsequent requests


as mentioned above, you can use thread pooling. And use future to process the returned results.
if you want to be more advanced. Just use message middleware. Implement request asynchronism. Cut the front and fill the valley


generally requires a thread pool, but now an additional thread is created for each request, which is very expensive.

for time-consuming tasks, it is recommended to improve throughput through queue decoupling and asynchronism. You can refer to this article

https://crossoverjie.top/%2F2.

Menu