当前位置: 首页 > news >正文

单页网站快速收录永州网站开发

单页网站快速收录,永州网站开发,外贸网站怎么做关键词,中国互联网协会官网平台目录 程序线程进程 并发并行​编辑 创建线程的基本方式 程序线程进程 并发并行 创建线程的基本方式#xff08;1#xff09; package com.edu.threaduse;public class Demo01 {public static void main(String[] args) throws InterruptedException {//创建Cat对象…目录 程序线程进程 并发并行​编辑 创建线程的基本方式 程序线程进程 并发并行 创建线程的基本方式1 package com.edu.threaduse;public class Demo01 {public static void main(String[] args) throws InterruptedException {//创建Cat对象可以当线程使用Cat cat new Cat();cat.start();//启动线程//使用run的话是主线程里面的一个普通方法,只有run执行完毕才结束//说明:当main线程启动一个子线程Thread-0,主线程不会阻塞会继续执行for (int i 0;i10;i){System.out.println(主线程ii);Thread.sleep(1000);}} } //通过继承Thread类创建线程 /* 当一个类继承类Thread类该类就可以当做线程使用 我们会重写run方法写上自己的业务代码 run Thread类实现Runnable接口的run方法*/ class Cat extends Thread{Overridepublic void run() {int time 0;while(time80){//重写run方法写上自己的业务逻辑//该线程每隔1秒在控制台输出喵喵我是小猫咪;System.out.println(喵喵,我是小猫咪线程名称Thread.currentThread().getName());//让线程休眠1stry {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}}} }创建线程的基本方式2  package com.edu.threaduse;public class Demo02 {public static void main(String[] args) { // Dog dog new Dog(); // //dog.start()无法使用 // Thread thread new Thread(dog); // thread.start();Tiger tiger new Tiger();ThreadProxy threadProxy new ThreadProxy(tiger);threadProxy.start();} } class Animal{} class Tiger extends Animal implements Runnable{Overridepublic void run() {System.out.println(老虎);} } class ThreadProxy implements Runnable{ //看成一个Thread代理类private Runnable target null;//属性Overridepublic void run() {if(target!null){target.run(); //运行类型为Tiger}}public ThreadProxy(Runnable target) {this.target target;}public void start(){start0();}public void start0(){run();} }class Dog implements Runnable{ //通过实现Runnable接口实现线程Overridepublic void run() {while(true){System.out.println(小狗叫);try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}}} } 售票超卖 package com.edu.ticket;public class SellTicket {public static void main(String[] args) {SellTick02 sellTick02 new SellTick02();new Thread(sellTick02).start();new Thread(sellTick02).start();new Thread(sellTick02).start();} }//class SellTick01 extends Thread{ // private static int ticketNum 100; // // Override // public void run() { // // while (true){ // if (ticketNum0){ // System.out.println(售票结束); // break; // } // System.out.println(售出一张还有:--ticketNum张); // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // throw new RuntimeException(e); // } // } // } //} class SellTick02 implements Runnable{private int ticketNum 100;Overridepublic void run() {while (true){if (ticketNum0){System.out.println(售票结束);break;}System.out.println(售出一张还有:--ticketNum张);try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}}} }线程终止 package com.edu.exit;public class ThreadExit_ {public static void main(String[] args) throws InterruptedException {T t1 new T();t1.start();//主线程休眠10s再通知Thread.sleep(10*1000);t1.setLoop(false);} } class T extends Thread{private boolean loop true;Overridepublic void run() {while(loop){try {Thread.sleep(50);} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println(AThread 运行中...);}}//方便主线程控制public void setLoop(boolean loop) {this.loop loop;} }常用方法 package com.edu.method;public class ThreadMethod_ {public static void main(String[] args) throws InterruptedException {T t new T();t.setName(老虎);t.setPriority(Thread.MIN_PRIORITY);System.out.println(t.getName());t.start();//主线程打印hi然后中断子线程for (int i 0;i5;i){Thread.sleep(1000);System.out.println(HI);}t.interrupt(); //中断t的休眠} } class T extends Thread{Overridepublic void run() {while (true){for (int i 0;i100;i){System.out.println(Thread.currentThread().getName()吃包子);}try {System.out.println(Thread.currentThread().getName()休眠中);Thread.sleep(20000);} catch (InterruptedException e) {//当线程执行道一个中断方法时可以加入自己的业务代码System.out.println(Thread.currentThread().getName()被中断了);}}}}package com.edu.method;public class ThreadMethod02 {public static void main(String[] args) throws InterruptedException {T1 t1 new T1();t1.start();for (int i 0;i20;i){if(i5){Thread.yield();//t1.join}System.out.println(HIi);Thread.sleep(1000);}} } class T1 extends Thread{private int loop 20;Overridepublic void run() {while (loop--0){System.out.println(Hello: loop);try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}}} }package com.edu.method;public class ThreadMethod03 {public static void main(String[] args) throws InterruptedException {T3 t new T3();Thread t1 new Thread(t);for (int i 1 ;i10;i) {System.out.println(hi:i);if (i5){t1.start();t1.join();}Thread.sleep(1000);}System.out.println(主进程结束);} } class T3 implements Runnable{Overridepublic void run() {for (int i1;i10;i){System.out.println(HELLO:i);try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}}System.out.println(子线程结束);} }
http://www.pierceye.com/news/804737/

相关文章:

  • 太原网站排名系统电子商务市场营销
  • 社区网站开发进度表2018年做网站还能
  • 论企业网站建设的必要性内网网站搭建设
  • 网站建设怎么翻译如何建立自己的网站
  • 2345网址大全热门seo推广排名稳定
  • 网站建设工作有底薪吗360优化大师
  • 门户网站微信服务号建设大型网站建设优化排名
  • 贵州省冶金建设有限公司网站wordpress end_lvl
  • 网站建设的工作职责是什么网站后台显示连接已重置
  • 俱乐部手机网站模板微信公众号个人可以做网站么
  • 简述一个网站开发流程软件下载网站搭建
  • 超级营销型网站模板建湖人才网官网登录
  • 建设网站都需要什么万网二手已备案域名
  • 网站建设运营维护合同快捷建站专家
  • 中山建设网站公司软件工程开发
  • 网站备案logo韩国展厅设计网站
  • 网站建设沧州做网站导航能赚钱吗
  • 自己怎么创建免费网站wordpress使用插件
  • 做一个个人主页的网站怎么做商城小程序模板
  • 网站站内链接怎么做wordpress文章样式插件
  • 网站大全浏览器济南免费网站建设优化
  • 招聘网站入职分析表怎么做网站关键字挖掘
  • 锡盟本地网站建设网站欢迎页面代码
  • 有做网站吗个人站长网站
  • 免费网站模板下载图怪兽在线制作
  • 黑龙江网站设计公司广告海外推广
  • 农产品网站建设策划国际新闻最新10条
  • 南通制作网站公司开发公司与物业公司移交协议
  • 做网站为什么很复杂最简单的免费网站制作模板
  • 高端网站公司书画工作室网站模板网站建设