首页 > TAG信息列表 > SellTicket

【Java】使用线程模拟卖票并解决安全问题

SellTicket.java package maipiao; public class SellTicket implements Runnable { private static int tickets = 100; private Object obj = new Object(); private int x = 0; @Override public void run() { while (true) {

两个线程交替输出内容

public class App { public static void main(String[] args) throws Exception { sellTicket s = new sellTicket(); Thread t1 = new Thread(s); Thread t2 = new Thread(s); t1.setName("t1"); t2.setName("t