With regard to multithreading, the principles provided on the network are very simple. It is nothing more than inheriting the thread class or implementing the runable interface. However, when I first processed it, it was difficult to understand it, for example, how the program supplements the tasks to be processed and how to enter the specific execution of multithreading.
Of course, because I implemented it on the basis of a senior engineer, many architecture problems do not need to be considered. With the underlying foundation, it is convenient to develop multi-threaded code at the upper layer. Since I do not understand it very well, I can only briefly explain the ideas and discuss them together.
First, solve the problem of multi-threaded task Source:
List <Task> tasks = dao. query ("select task from Task task where task. taskType = 'attachment' and task. finishTime is null "}
The solution here is to create a table, read all the tasks to be processed, and read them from the table when the program is executed (the finishTime has a value after the task is executed, so the difference between a task to be processed and a task to be processed is whether the finishTime is empty)
All pending tasks will be added to the java. util. concurrent. ThreadPoolExecutor of the thread pool.
Then there is the specific program execution process.
(Task. getFinishTime ()! === Work () Exception;
In this way, if you have any new multi-threaded task, you only need to inherit the class above and then implement your own work method.
Of course, some trivial problems need to be solved during the entire process, and this is solved by yourself. The overall idea is probably like this, hoping to help you understand multithreading.