- public static void main(String[] args) {
- 13. //产生4个普通窗口
- 14. for(int i=1;i<5;i++){
- 15. ServiceWindow window = new ServiceWindow();
- 16. window.setNumber(i);
- 17. window.start();
- 18. }
- 19. 问题: 但是,start()方法里面是有个while(true)循环。下面的代码怎么会执行到呢?? ??
- 20. //产生1个快速窗口
- 21. ServiceWindow expressWindow = new ServiceWindow();
- 22. expressWindow.setType(CustomerType.EXPRESS);
- 23. expressWindow.start();
- 24.
- 25. //产生1个VIP窗口
- 26. ServiceWindow vipWindow = new ServiceWindow();
- 27. vipWindow.setType(CustomerType.VIP);
- 28. vipWindow.start();
- public void start(){
- 28. Executors.newSingleThreadExecutor().execute(
- 29. new Runnable(){
- 30. public void run(){
- 31. //下面这种写法的运行效率低,最好是把while放在case下面
- 32. while(true){
- 33. switch(type){
- 34. case COMMON:
- 35. commonService();
- 36. break;
- 37. case EXPRESS:
- 38. expressService();
- 39. break;
- 40. case VIP:
- 41. vipService();
- 42. break;
- 43. }
- 44. }
- 45. }
- 46. }
- 47. );
- 48. }
复制代码
start()方法里面是有个while(true)循环。下面的代码怎么会执行到呢?? ?? |