Java基础入学考blog-11
2014-07-31 22:21
197 查看
张孝祥_7k月薪面试题破解之一_交通灯管理系统视频----笔记心得
面向对象设计把握一个重要的经验:谁拥有数据,谁就对外提供操作这些数据的方法Stone--->StoneKnife 石头变成石刀,通过磨刀工厂。
StoneKnife =KnifeFactory.createKnife(stone){ ...;return StoneKnife};
内部类访问外部类成员变量,外部累成员变量必须是私有的,另一种方法:外部类名.this.成员变量名
随机数:new Random.nextInt(10) 10为0--9.
JDK1.5创建启动线程新特性
ExecutorService pool = Executors.newSingleThreadExecutor(); //线程池
pool.execute(new Runnable(){
public void run(){
for(int i=1;i<1000;i++){
try {
Thread.sleep((new Random().nextInt(10) + 1) * 1000); 路上随机时间增加车辆
} catch (InterruptedException e) {
e.printStackTrace();
}
vechicles.add(Road.this.name + "_" + i);
}
}
});
创建定时移走车辆
ScheduledExecutorService timer = Executors.newScheduledThreadPool(1); //定时类 1是数量
timer.scheduleAtFixedRate( //四个参数,1:执行任务,2:首次执行时间。3,每个多长时间再次执行。4:时间数量单位
new Runnable(){
public void run(){
if(vechicles.size()>0){
boolean lighted = Lamp.valueOf(Road.this.name).isLighted();
if(lighted){
System.out.println(vechicles.remove(0) + " is traversing !");
}
}
}
},
1,
1,
TimeUnit.SECONDS);
相关文章推荐
- Java基础入学考blog-5
- Java基础入学考blog-9
- Java基础入学考blog-4
- Java基础入学考blog-8
- Java基础入学考blog-2
- Java基础入学考blog-6
- Java基础入学考blog-10
- Java基础入学考blog-3
- Java基础入学考blog-7
- Java基础入学考blog-1
- 黑马程序员_java基础11-GUI
- JAVA 基础学习(11)
- Java基础11 对象引用
- java基础要点(11)-包
- 黑马程序员_java基础加强11_空中网题解_自己做的答案
- java基础--11
- android面试集锦-java基础11
- 黑马程序员—11、JAVA基础&网络编程
- 黑马程序员_Java基础11
- java基础问题11