ExecutorService的装饰器模式
2016-06-24 21:04:27 0 举报
装饰器模式是一种结构型设计模式,它允许在运行时动态地添加或修改对象的行为。在Java中,ExecutorService是一个接口,它提供了一种将任务提交到线程池的机制。装饰器模式可以用于扩展ExecutorService的功能,例如添加日志记录、异常处理等功能。 在Java中,可以使用ThreadPoolExecutor类来实现装饰器模式。ThreadPoolExecutor类继承自AbstractExecutorService类,它提供了一种创建线程池的方法。通过使用ThreadPoolExecutor类,可以在运行时动态地添加或修改线程池的行为。
作者其他创作
大纲/内容
ThreadPoolDecorator
- service : ExecutorService
+ ThreadPoolDecorator(ExecutorService service)
AbstractExecutorService
MonitorableThreadPoolExecutor
- frequenceStatistic : FrequenceStatistic- lastFreq : volatile int- currentFreq : volatile int- threadsStatistic : QueueFuture- detectQueue : Queue- threadNumState : ThreadNumState
+ balanceThreads() : void- increaseThreadsNum() : boolean- decreaseThreadsNum() : boolean
ExecutorService
+ submit(Runnable task) : Future+ shutdown() : void
ThreadPoolExecutor
+ getPoolSize() : int
0 条评论
下一页