Executor Framework
文章平均质量分 68
czjuttsw
Learning, staying up to date, and working on the latest and greatest in languages and APIs is what keeps me excited.
展开
-
使用Lock实现互斥(synchronized的一个替代)
传说有一本江湖罕见的武功秘籍,该书珍藏在主持大师手中。一天大师盛情邀请江湖好汉前来观摩该书,但是一次只能有一个人来看。 该怎么办呢?用synchronized来实现吗?都用臭了,算了。用下李狗(Doug Lea)写的Lock吧。 实现很简单,首先获得一个锁实例 Lock lock = new ReentrantLock(); 接着获得一把锁: lock.lock(); 观摩该书中。。原创 2013-02-17 15:20:22 · 2378 阅读 · 1 评论 -
Executor内部如何创建线程?
对于Thread,它既是工作单元(含有run方法),也是执行机制(start方法)。而executor framework将两者解耦,实现了工作单元和执行机制的分离。executor负责执行任务,runnable和callable代表业务逻辑单元(前者无返回值,后者有返回值)。使用executor framework,我们无须再手动创建Thread,因为executor framework有一个专原创 2013-02-18 09:29:16 · 2433 阅读 · 1 评论 -
Executor 生命周期
对于生命周期,我想我们已经听得够多了。比如Android的Activity生命周期(onCreate->onStart->onResume...),比如Servlet容器中的Servlet生命周期(init->service->destroy)。 了解一个对象的生命周期,会加深你对该对象所属框架的认识。因此,要想掌握某个对象,了解它的生命周期是必要的。 对于executor framework原创 2013-02-18 14:29:31 · 4164 阅读 · 0 评论