public class ticketrunnablethread implements runnable {
private int ticket = 1000;
public void run() {
for (int i = 0; i < 1000; i++) {
if (ticket > 0) {
system.out.println("ticket=" + ticket-- + "," + thread.currentthread().getname());
}
}
}
}
启动三个线程
ticketrunnablethread ticketrunnablethread = new ticketrunnablethread();
new thread(ticketrunnablethread).start();
new thread(ticketrunnablethread).start();
new thread(ticketrunnablethread).start();