Java Timer 对象创建后使用Timer更改其属性!!!

首先来个简单那的实例:

 

 

我们以一个实例思考,车站,每辆车只能停靠10分钟就必须出站.传统方式,我们是以车站为单位,通过多线程来控制每辆车的出站情况!

 

输出:

the bus station hava 0 cars !
Fri May 21 14:53:58 CST 2010 : a car[car01] into the bus station !
Bus [car01] :: in station !
the bus station hava 1 cars !
Fri May 21 14:54:02 CST 2010 : a car[car02] into the bus station !
Bus [car01] :: in station !
Bus [car02] :: in station !
the bus station hava 2 cars !
Fri May 21 14:54:08 CST 2010 : a car[car01] left the bus station !
Fri May 21 14:54:08 CST 2010 : a car[car03] into the bus station !
Bus [car02] :: in station !
Bus [car03] :: in station !
the bus station hava 2 cars !
Fri May 21 14:54:12 CST 2010 : a car[car02] left the bus station !
Bus [car03] :: in station !
the bus station hava 1 cars !
Fri May 21 14:54:18 CST 2010 : a car[car03] left the bus station !

 

 

现在我们可以使用Java Timer来从每辆车自身来处理!

 

 

打印:

the bus station hava 0 cars !
Fri May 21 14:57:11 CST 2010 : a car[car01] into the bus station !
Bus [car01] :: in station !
the bus station hava 1 cars !
Fri May 21 14:57:15 CST 2010 : a car[car02] into the bus station !
Bus [car01] :: in station !
Bus [car02] :: in station !
the bus station hava 2 cars !
Fri May 21 14:57:21 CST 2010 : a car[car01] left the bus station !
Fri May 21 14:57:21 CST 2010 : a car[car03] into the bus station !
Bus [car02] :: in station !
Bus [car03] :: in station !
the bus station hava 2 cars !
Fri May 21 14:57:25 CST 2010 : a car[car02] left the bus station !
Bus [car03] :: in station !
the bus station hava 1 cars !
Fri May 21 14:57:31 CST 2010 : a car[car03] left the bus station !

但仔细想想,其实这2种方式,是完全一致的!!!仅供参考!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值