public class Demo2 implements Runnable { int i=0; @Override public void run() { while (true) { synchronized (this) { notify(); if (i < 100) { i++; System.out.println(Thread.currentThread().getName() + "票号是:" + i); } else { break; } try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } } public static void main(String[] args) { Demo2 demo2=new Demo2(); Thread t1=new Thread(demo2,"线程1售出的"); Thread t2=new Thread(demo2,"线程2售出的"); Thread t3=new Thread(demo2,"线程3售出的"); t1.start(); t2.start(); t3.start(); } }
线程实现三个窗口同时售票用实现Runnable方式
最新推荐文章于 2024-04-23 18:52:22 发布