COMMAND(命令)— 对象行为型模式

来源:互联网 发布:网络爬虫用什么语言 编辑:程序博客网 时间:2024/05/17 02:17

GoF解释:将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤消的操作。


Java示例:java.util.concurrent.Excecutor。

该接口暴露了要执行的单一方法:void execute(Runnable command)用于执行已提交的 Runnable 任务。此接口提供一种将任务提交与每个任务将如何运行的机制(包括线程使用的细节、调度等)分离开来的方法。


使用范例:
Executor executor = anExecutor;
executor.execute(new RunnableTask1());
executor.execute(new RunnableTask2());


0 0