File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import Thread .Bank .system .DoCall ;
44
5- import javax .print .Doc ;
6- import java .util .ArrayList ;
7- import java .util .List ;
5+
86
97/**
108 * Created by szh on 2017/5/8.
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public void doSpend() {
1313 if (Store .queue .isEmpty ()) {
1414 executor .shutdownNow ();
1515 } else {
16- executor .execute (new PopWindows ( )); // 执行操作任务
16+ executor .execute (new ServiceWindows ( Store . queue . poll () )); // 执行操作任务
1717 }
1818 }
1919}
Original file line number Diff line number Diff line change @@ -30,17 +30,21 @@ private void init(){
3030 while (!Store .queue .isEmpty ()){
3131// System.out.println("队列是否为空+!"+!Store.queue.isEmpty());
3232// bankSystem.doSpend();
33- this .executorService .execute (new PopWindows ( ));
33+ this .executorService .execute (new ServiceWindows ( Store . queue . poll () ));
3434 }
3535// System.out.println("已经执行到这里了");
3636
3737 }
3838 public static void main (String args []) throws InterruptedException {
3939 InitBank initBank =new InitBank ();
4040 initBank .init ();
41- Thread .sleep (1000 );
42- if (Store .queue .isEmpty ())
43- initBank .executorService .shutdownNow ();
44-
41+ Thread .currentThread ().sleep (20000 );// 需要设置长时间,否则导致main方法结束后的下面方法结束了线程池
42+ // if (Store.queue.isEmpty()) {
43+ // try {
44+ // initBank.executorService.shutdownNow();
45+ // } catch (java.lang.NullPointerException e) {
46+ // System.out.println("一经被捕捉");
47+ // }
48+ // }
4549 }
4650}
Original file line number Diff line number Diff line change @@ -17,8 +17,12 @@ public void run() {
1717 }
1818
1919 public void spend () throws InterruptedException {
20- int nowNUm =Store .queue .poll ();
21- System .out .println ("线程:" + Thread .currentThread ().getName () + "正在为" + nowNUm + "服务" );
22- Thread .currentThread ().sleep (1000 );
20+ if (!Store .queue .isEmpty ()) {
21+ int nowNUm = Store .queue .poll ();
22+ System .out .println ("线程:" + Thread .currentThread ().getName () + "正在为" + nowNUm + "服务" );
23+ Thread .currentThread ().sleep (1000 );
24+ }else {
25+ System .out .println ("当前一经没有客户" );
26+ }
2327 }
2428}
Original file line number Diff line number Diff line change 1+ package Thread .elevator ;
2+
3+ /**
4+ * Created by szh on 2017/5/10.
5+ */
6+ public class EevatorControll {
7+
8+ }
Original file line number Diff line number Diff line change 1+ package Thread .elevator ;
2+
3+ /**
4+ * Created by szh on 2017/5/10.
5+ */
6+ public class Elevator {
7+ private int NowNum ;
8+
9+ public Elevator () {
10+ }
11+
12+ public int getNowNum () {
13+ return NowNum ;
14+ }
15+
16+ public void setNowNum (int nowNum ) {
17+ NowNum = nowNum ;
18+ }
19+ public void elevatorUp (){
20+ if (this .NowNum == 10 ){
21+ System .out .println ("已经到达最高层" );
22+ return ;
23+ }
24+ this .NowNum =this .NowNum +1 ;
25+ }
26+ public void elevatorDown (){
27+ if (this .NowNum == 0 ){
28+ System .out .println ("已到达最底层" );
29+ return ;
30+ }
31+ this .NowNum =this .NowNum - 1 ;
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ package Thread .elevator ;
2+
3+ /**
4+ * Created by szh on 2017/5/10.
5+ */
6+ public class ElevatorTest {
7+ public static void main (String args []){
8+ Elevator elevator =new Elevator ();
9+ elevator .setNowNum (10 );
10+ elevator .elevatorDown ();
11+ System .out .println (elevator .getNowNum ());
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments