Java多线程之实现Runnable接口

 

 1 package org.study2.javabase.ThreadsDemo.runnable;
 2 
 3 /**
 4  * @Auther:GongXingRui
 5  * @Date:2018/9/18
 6  * @Description:通过实现Runnable接口实现多线程
 7  **/
 8 public class TicketApp {
 9     public static void main(String args[]) {
10         Ticket ticket = new Ticket();
11         Thread t1 = new Thread(ticket, "小红");
12         Thread t2 = new Thread(ticket, "明明");
13         t1.start();
14         t2.start();
15     }
16 }
17 
18 class Ticket implements Runnable {
19 
20     @Override
21     public void run() {
22         int num = 1;
23         while (num < 50) {
24             System.out.println(Thread.currentThread().getName() + "抢到票:" + num);
25             num++;
26         }
27     }
28 }

 

posted @ 2018-09-18 15:39  星瑞  阅读(223)  评论(0编辑  收藏  举报