本帖最后由 张子凯 于 2013-5-7 08:53 编辑
- package com.isoftstone.interview.traffic;
- import java.util.concurrent.Executors;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.concurrent.TimeUnit;
- public class LampController {
- private Lamp currentLamp;
-
- public LampController(){
- //刚开始让由南向北的灯变绿;
- currentLamp = Lamp.S2N;
- currentLamp.light();
-
- /*每隔10秒将当前绿灯变为红灯,并让下一个方向的灯变绿*/
- ScheduledExecutorService timer = Executors.newScheduledThreadPool(1);
- timer.scheduleAtFixedRate(
- new Runnable(){
- public void run(){
- System.out.println("来啊");
- currentLamp = currentLamp.blackOut();
- }
- },
- 10,
- 10,
- TimeUnit.SECONDS);
- }
- }
复制代码 这段代码是张孝祥老师的交通灯中的,
ScheduledExecutorService timer = Executors.newScheduledThreadPool(1);这段代码我又点疑问。ScheduledExecutorService 跟Executors都是接口,也就是说内部的成员函数都没实现,为什么可以调用呢?
|
|