# Thread-Flow **Repository Path**: gepengjun/thread-flow ## Basic Information - **Project Name**: Thread-Flow - **Description**: 线程编排的小工具. 可以执行任意串并行组合的线程.;支持单个单元的超时控制;每个单元可以有自己的参数及返回值. 支持单个单元结果的异步回调. 支持总体任务的超时调用及总体任务结束后的结果调用;支持动态的决定不必要再执行的单元跳过执行, 将不必要继续执行而正在执行的线程进行中断 每个单元适用在不同的任务编排中 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 18 - **Forks**: 4 - **Created**: 2021-01-19 - **Last Updated**: 2024-11-18 ## Categories & Tags **Categories**: utils **Tags**: None ## README # ThreadFlow #### introduce Thread arrange tool. Can execute any string parallel combination of threads; Each unit can have its own parameters and return values. It supports asynchronous callback of single unit results. It supports the timeout control of single unit; It Support the timeout call of the overall task and the result call after the completion of the overall task; It supports the dynamic decision to skip the execution of units that have not been executed and do not need to be executed any more, and it can also interrupt the thread that is executing but does not need to continue; Each unit can be used in different task choreography; Supports dynamic modification of post units; If you have any good suggestions, please leave a message; If you like it or if it's helpful, make a star :) #### Software architecture Understanding this project can be seen from the test cases in test. Basic functions: **1. Serial thread call** :   1.1. order of execution           A -> B -> C        the cost of the execution   1      1      1     unit:second        exceptionally                      N    N    N    Expect: the unit C executes after the unit B executes after the unit A   1.2. order of execution           A -> B -> C        the cost of the execution   1      1      1     unit:second        exceptionally                      N    Y    N    Expect: the unit B executes exceptionally after the unit A executes successfully, the unit C direct to be exceptional to void execution **2. Simple parallel call:**   2.1 all are unnecessary for next        unit A,B,C are all unnecessary for unit D, then the unit D executes after the first executes successfully in A,B,C       A --unnecessary successful 1 second-->       B --unnecessary successful 2 second--> D --successful 0.5 second--       C --unnecessary successful 2 second-->     Expect: the unit D executes after the unit A executes successfully, the set the execute state of B,C to be exceptional,after about 1.5 seconds we can get the result of the unit D.   2.2 some are necessary and some are unnecessary for next       unit A is necessary for unit D, and the unit B,C are unnecessary for unit D. then the unit A firstly execute successfully, and the unit D does not to execute at this time until after the first executes successfully in B,C       A --necessary   successful 1 second-->       B --unnecessary successful 2 second--> D --successful 0.5 second--       C --unnecessary successful 2 second-->     Expect: the unit D executes after the first executes successfully in B,C. we can get the result in 2.5 seconds.   2.3 all are necessary for next       unit A,B,C are all necessary for unit D, then the unit D executes after the last executes successfully in A,B,C       A -- necessary   successful 1 second-->       B -- necessary   successful 2 second--> D --successful 0.5 second--       C -- necessary   successful 3 second-->     Expect: D executes after the unit C executes successfully 2.4 all are necessary for next but one of the previous executes exceptionally        the unit A is necessary for the unit D, executes successfully in 1 second;        the unit B is necessary for the unit D, executes exceptionally in 1 second;        the unit C is necessary for the unit D, executes successfully in 2 second;       A -- necessary   successful 1 second-->       B -- necessary   exceptional 1 second--> D --successful 0.5 second--       C -- necessary   successful 2 second-->     Expect: the unit D direct set the self's execute state to be exceptional to void execution and set the unit C's execute state to be exceptional after the unit B executes exceptionally **3. Serial parallel combination**       A --1 second-->                                 C -- unnecessary 1 second-->       B --1 second-->                                                                                                F---->       D --10 second-->E -- unnecessary 1 second-->     the unit A,B,D start at the same time.     at last the unit F executes after the unit C executes successfully     and set the unit E's sexecute state to be exceptional to void execution     and set the unit D's execute state to be exceptional     and interrupts the the unit D's thread if the unit D's enableInterrupted is true. **4. WorkHandler can be expanded** example:     1. let the current work executes after the previous executes exceptionally     2. we can add next work depends on the execute state of the current work