读书人

Java 多线程合作

发布时间: 2012-11-01 11:11:32 作者: rapoo

Java 多线程协作

?

?

汉堡容器: HambergFifo

???

?

顾客: Customer

??

?

测试类: HambergShop

???

Cooker 1:There are 1 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 2 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2:There are 3 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2:There are 4 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 5 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 1:There are 6 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 7 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 1:There are 8 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2:There are 9 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 10 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2: Hamberg Pool is Full, Stop making hamberg### Cooker: pool.wait()Cooker 1: Hamberg Pool is Full, Stop making hamberg### Cooker: pool.wait()Cooker 3: Hamberg Pool is Full, Stop making hamberg### Cooker: pool.wait()Customer1: I Got 1 Hamberg #1 cooked by Cooker 1Customer1: There are still 9 hambergs leftCustomer3: I Got 1 Hamberg #1 cooked by Cooker 3Customer1: I'm eating the hamberg for 7285 millisecondsCustomer3: There are still 8 hambergs leftCustomer3: I'm eating the hamberg for 4405 millisecondsCustomer2: I Got 1 Hamberg #1 cooked by Cooker 2Customer2: There are still 7 hambergs leftCustomer2: I'm eating the hamberg for 3170 millisecondsCustomer2: I Got 2 Hamberg #2 cooked by Cooker 2Customer2: There are still 6 hambergs leftCustomer2: I'm eating the hamberg for 6200 millisecondsCustomer3: I Got 2 Hamberg #2 cooked by Cooker 3Customer3: There are still 5 hambergs leftCustomer3: I'm eating the hamberg for 1260 millisecondsCustomer3: I Got 3 Hamberg #2 cooked by Cooker 1Customer3: There are still 4 hambergs leftCustomer3: I'm eating the hamberg for 5045 millisecondsCustomer1: I Got 2 Hamberg #3 cooked by Cooker 3Customer1: There are still 3 hambergs leftCustomer1: I'm eating the hamberg for 5835 millisecondsCustomer2: I Got 3 Hamberg #3 cooked by Cooker 1Customer2: There are still 2 hambergs leftCustomer2: I'm eating the hamberg for 3255 millisecondsCustomer3: I Got 4 Hamberg #3 cooked by Cooker 2Customer3: There are still 1 hambergs leftCustomer3: I'm eating the hamberg for 8265 millisecondsCustomer2: I Got 4 Hamberg #4 cooked by Cooker 3Customer2: There are still 0 hambergs leftCustomer2: I'm eating the hamberg for 5525 millisecondsjava.lang.Exception: Customer1: OH MY GOD!!!! No hambergs left, Waiter![Ring the bell besides the hamberg pool]### Customer: waiter.wait(): Sorry, Sir, there is no hambergs left, please wait!Customer1: OK, Waiting for new hambergsCooker 2:There are 1 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 1:There are 2 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 3 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Customer1: I Got 3 Hamberg #4 cooked by Cooker 2Customer1: There are still 2 hambergs leftCustomer1: I'm eating the hamberg for 14410 millisecondsCooker 2:There are 3 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 4 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 1:There are 5 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Customer2: I Got 5 Hamberg #4 cooked by Cooker 1Customer2: There are still 4 hambergs leftCustomer2: I'm eating the hamberg for 6620 millisecondsCustomer3: I Got 5 Hamberg #5 cooked by Cooker 3Customer3: There are still 3 hambergs leftCustomer3: I'm eating the hamberg for 14530 millisecondsCooker 1:There are 4 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 5 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2:There are 6 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2:There are 7 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 1:There are 8 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 9 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2:There are 10 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 1: Hamberg Pool is Full, Stop making hamberg### Cooker: pool.wait()Cooker 3: Hamberg Pool is Full, Stop making hamberg### Cooker: pool.wait()Customer2: I Got 6 Hamberg #5 cooked by Cooker 2Customer2: There are still 9 hambergs leftCustomer2: I'm eating the hamberg for 7865 millisecondsCooker 2:There are 10 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2: Hamberg Pool is Full, Stop making hamberg### Cooker: pool.wait()Customer1: I Got 4 Hamberg #6 cooked by Cooker 3Customer1: There are still 9 hambergs leftCustomer1: I'm eating the hamberg for 7460 millisecondsCustomer2: I Got 7 Hamberg #5 cooked by Cooker 1Customer2: There are still 8 hambergs leftCustomer2: I'm eating the hamberg for 5680 millisecondsCustomer3: I Got 6 Hamberg #6 cooked by Cooker 1Customer3: There are still 7 hambergs leftCustomer3: I'm eating the hamberg for 940 millisecondsCustomer3: I Got 7 Hamberg #7 cooked by Cooker 3Customer3: There are still 6 hambergs leftCustomer3: I'm eating the hamberg for 4880 millisecondsCustomer1: I Got 5 Hamberg #6 cooked by Cooker 2Customer1: There are still 5 hambergs leftCustomer1: I'm eating the hamberg for 1400 millisecondsCustomer2: I Got 8 Hamberg #7 cooked by Cooker 2Customer2: There are still 4 hambergs leftCustomer2: I'm eating the hamberg for 2955 millisecondsCustomer1: I Got 6 Hamberg #7 cooked by Cooker 1Customer1: There are still 3 hambergs leftCustomer1: I'm eating the hamberg for 5305 millisecondsCustomer3: I Got 8 Hamberg #8 cooked by Cooker 3Customer3: There are still 2 hambergs leftCustomer3: I'm eating the hamberg for 12830 millisecondsCustomer2: I Got 9 Hamberg #8 cooked by Cooker 2Customer2: There are still 1 hambergs leftCustomer2: I'm eating the hamberg for 14400 millisecondsCustomer1: I Got 7 Hamberg #9 cooked by Cooker 2Customer1: There are still 0 hambergs leftCustomer1: I'm eating the hamberg for 7720 millisecondsjava.lang.Exception: Customer1: OH MY GOD!!!! No hambergs left, Waiter![Ring the bell besides the hamberg pool]### Customer: waiter.wait(): Sorry, Sir, there is no hambergs left, please wait!Customer1: OK, Waiting for new hambergsjava.lang.Exception: Customer3: OH MY GOD!!!! No hambergs left, Waiter![Ring the bell besides the hamberg pool]### Customer: waiter.wait(): Sorry, Sir, there is no hambergs left, please wait!Customer3: OK, Waiting for new hambergsCooker 3:There are 1 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 1:There are 2 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2:There are 3 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Customer1: I Got 8 Hamberg #9 cooked by Cooker 3Customer1: There are still 2 hambergs leftCustomer1: I'm eating the hamberg for 8995 millisecondsCustomer3: I Got 9 Hamberg #8 cooked by Cooker 1Customer3: There are still 1 hambergs leftCustomer3: I'm eating the hamberg for 5240 millisecondsCooker 1:There are 2 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 2:There are 3 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Cooker 3:There are 4 Hambergs in all### Cooker: waiter.notifyAll() : Hi! Customers, we got some new Hambergs!Customer2: I Got 10 Hamberg #10 cooked by Cooker 2Customer2: There are still 3 hambergs leftCustomer2: I'm eating the hamberg for 10590 milliseconds

?

?

读书人网 >编程

热点推荐