Java 是否有一种设计模式来控制从作业或从主作业管理从作业?

Java 是否有一种设计模式来控制从作业或从主作业管理从作业?,java,algorithm,oop,design-patterns,Java,Algorithm,Oop,Design Patterns,管理或控制器设计模式。我有一个班在结构上做两种不同的工作。是否有一种设计模式可以以更易于维护的方式对其进行重构?或者,我应该如何以更可维护的方式划分这个类 Management Class does Task launching recovery management - create Callable Task - if thread failed to sta

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

                     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:

事实上,在你的情况下,你的实际班级做得太多了:它有三个职责:

配置线程池 启动任务 恢复失败的任务 我会把你的全班分成三个班:

设置设置 任务执行器启动器 失败的taskrecover恢复程序
请注意,这不是设计模式,而是原则的一部分。

我如何知道其他类中的线程状态?如果我向其他类注入依赖项,我将创建耦合,不是吗?您可能希望实现一个等待/通知机制来通知线程状态,或者只是有一个未来的参考来知道是否存在异常或成功。@Georgethathson并非所有耦合都是固有的坏-如果所有代码都完全解耦,它根本无法沟通!Mik378关于利用未来的建议是一个很好的建议。