本帖最后由 lilylikejack 于 2013-8-9 17:14 编辑
- class Ticket implements Runnable
- {
- private int tick =40;
- public void run()
- {
- while(true)
- {
- if(tick>0)
- {
- System.out.println(Thread.currentThread().getName()+"...sale:"+tick--);
-
- }
- }
- }
- }
- class TicketDemo
- {
- public static void main(String[] args)
- {
- Ticket t = new Ticket();
- Thread t1 = new Thread(t);
- Thread t2 = new Thread(t);
- Thread t3 = new Thread(t);
- Thread t4 = new Thread(t);
- t1.start();
- t2.start();
- t3.start();
- t4.start();
- }
- }
复制代码 听的感觉差不多,自己敲了一遍代码 我想在票卖完的时候加一句打印一句“票已售完”该加在哪里。。自己常识加了几次都失败了 |