是否存在一种设计模式来控制从作业或从主作业管理从作业



管理或控制器设计模式。我有一个班在结构上做两种不同的工作。是否有一种设计模式可以以更易于维护的方式重构它?或者,我应该如何以更易于维护的方式划分这个类?

                     Management Class does
Task launching                            recovery management
- create Callable Task                   - if thread failed to start, re-assign 
- submit tasks to ExecutorService              the same task to other thread 
- start ExecutorService                  - if task is not halted unexpectedly,
- get result of each task                      re-assign the task to new thread
                                         - if thread halted, get already done 
                                               job and restart the thread for
                                               not done jobs
                                         - other task and thread related recovery
                                               scenarios
Settings
- set requirements of management class in system level
- determine optimal number of threads should be run
- determine optimal number of task to be created
- create and manage system configuration file - store system settings, get system
  settings-

在拒绝投票或试图关闭之前,如果你是建设性的,请写下评论,以便我修复它。

您需要应用SRP: Single Responsibility原则

事实上,在你的例子中,你的实际类做得太多了:它有三个职责:

    配置线程池启动任务
  1. 恢复失败的任务

我会把你们全班分成三个班:

  1. 设置(设置)
  2. TaskExecutor(发射器)
  3. FailedTaskRecoverer(回收器)

请注意,这不是一个设计模式,而是SOLID原则的一部分。

最新更新