当前位置: 首页 > 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.zqtcl.cn/news/804737/

相关文章:

  • 个人网站课程设计报告app免费制作软件中文版
  • 品牌建设网站规划盛唐网站建设
  • 商城网站系统建站平台上建设的网站可以融资吗
  • 怎么查网站空间wordpress快速入门
  • 长沙 网站运营德国服务器网站
  • 有动效网站建网站的书籍
  • 网站模版更新公告2023年ppt模板免费
  • 广饶网站建设北京建设工程监督网站
  • 长沙网站建设电话郑州网站空间
  • 做网站是怎样赚钱的网页制作工具按其制作方式有
  • 网站地图在哪里展现电子商务网站需要做那些准备工作
  • 深圳网站设计收费标准中端网站建设公司
  • 有关wordpress教学的网站wordpress返回旧版
  • php做网站弊端wordpress强大播放器
  • 怎么直接做免费网站wordpress如何自建站
  • 中国建设银行建银购网站金堂企业网站建设
  • 手机微网站开发的目的和意义温州公司网站开发
  • 除了外链 还有什么办法使网站提高排名网站建设珠海 新盈科技
  • 几分钟弄清楚php做网站中国风景摄影网
  • 卡片式网站网页设计公司的市场评估
  • 网站开发的感想wordpress水煮鱼
  • 网站开发入门培训机构自豪地采用wordpress更改
  • 手机网站来几个最近的国际新闻大事件
  • 重庆网站开发设计公司电话资源网站优化排名
  • 国土分局网站建设方案外贸seo网站
  • 营销型网站建设易网拓烟台h5网站建设公司
  • PHP网站开发都需要学什么中介网站模板
  • 网站建设与维护模板官方网站建设费用应入什么科目
  • 网站建设企业关键词seo关键词库
  • 美容院网站源码wordpress scandir