Runnable
Runnable接口
package ziboshizhangdianqu; class Ticket implements Runnable{ private int num=10; @Override public synchronized void run() { // TODO Auto-generated method stub for(int i=0;i<10;i++){ System.out.println(Thread.currentThread().getName()+"买了第"+num+"张票"); num--; } } } public class Dxc1 { public static void main(String[] args) { Ticket ticket=new Ticket(); new Thread(ticket,"t1").start(); new Thread(ticket,"t2").start(); new Thread(ticket,"t3").start(); } }
运行结果: