/*
    例子:创建三个窗口卖票,总共100张

    /

    1. package com.atguigu.java1;
    2. /**
    3. *例子:创建三个窗口卖票,总共100张
    4. *存在线程安全问题,待解决
    5. *
    6. * @author Dxkstart
    7. * @create 2021-05-06 16:46
    8. */
    9. public class WindowTest {
    10. public static void main(String[] args) {
    11. Window w1 = new Window();
    12. Window w2 = new Window();
    13. Window w3 = new Window();
    14. w1.start();
    15. w2.start();
    16. w3.start();
    17. }
    18. }
    19. class Window extends Thread {
    20. private static int ticket = 100;//票数
    21. @Override
    22. public void run() {
    23. while(true){
    24. if(ticket > 0){
    25. System.out.println(getName() + ": 卖票,票号为" + ticket);
    26. ticket --;
    27. }else{
    28. break;
    29. }
    30. }
    31. }
    32. }