码迷,mamicode.com
首页 > 编程语言 > 详细

java 多线程

时间:2020-04-04 09:39:20      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:nms   char   read   charset   ide   pat   ike   public   swt   

package com.jack.test2;

public class MyRunnable implements Runnable {

    int tikets = 20;

    @Override
    public void run() {
        while (true) {
            if (tikets > 0) {
                System.out.println(Thread.currentThread().getName() + "卖票中:第" + (21 - tikets) + "张票");

                tikets--;
            }

        }
    }
}
package com.jack.test2;


public class main {

    public static void main(String[] args) {
        MyRunnable run= new MyRunnable();

        Thread r1 = new Thread(run);
        Thread r2 = new Thread(run);

        r1.start();
        r2.start();


    }


}
"D:\Program Files (x86)\Java\jdk1.8.0_71\bin\java.exe" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2018.3.3\lib\idea_rt.jar=59348:D:\Program Files\JetBrains\IntelliJ IDEA 2018.3.3\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\charsets.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\deploy.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\access-bridge-32.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\cldrdata.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\dnsns.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\jaccess.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\jfxrt.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\localedata.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\nashorn.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\sunec.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\sunjce_provider.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\sunmscapi.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\sunpkcs11.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\ext\zipfs.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\javaws.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\jce.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\jfr.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\jfxswt.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\jsse.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\management-agent.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\plugin.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\resources.jar;D:\Program Files (x86)\Java\jdk1.8.0_71\jre\lib\rt.jar;D:\users\ligenyun\IdeaProjects\Test\out\production\day1" com.jack.test2.main
Thread-0卖票中:第1张票
Thread-1卖票中:第1张票
Thread-1卖票中:第3张票
Thread-1卖票中:第4张票
Thread-0卖票中:第2张票
Thread-1卖票中:第5张票
Thread-0卖票中:第6张票
Thread-1卖票中:第7张票
Thread-0卖票中:第8张票
Thread-1卖票中:第9张票
Thread-0卖票中:第10张票
Thread-1卖票中:第11张票
Thread-0卖票中:第12张票
Thread-1卖票中:第13张票
Thread-0卖票中:第14张票
Thread-1卖票中:第15张票
Thread-0卖票中:第16张票
Thread-1卖票中:第17张票
Thread-0卖票中:第18张票
Thread-1卖票中:第19张票
Thread-0卖票中:第20张票

 

java 多线程

标签:nms   char   read   charset   ide   pat   ike   public   swt   

原文地址:https://www.cnblogs.com/ligenyun/p/12630240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!