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

荆门公司做网站ui设计流程培训怎么样

荆门公司做网站,ui设计流程培训怎么样,网络推广山东,海运外贸流程线程的实现方式 继承Thread类#xff1a;void run()方法没有返回值#xff0c;无法抛异常实现Runnable接口#xff1a;void run()方法没有返回值#xff0c;无法抛异常实现Callable接口#xff1a;V call() throws Exception 返回结果#xff0c;能够抛异常 实现Callab…线程的实现方式 继承Thread类void run()方法没有返回值无法抛异常实现Runnable接口void run()方法没有返回值无法抛异常实现Callable接口V call() throws Exception 返回结果能够抛异常 实现Callable接口 1创建Callable接口的实现类并实现call()方法该call()方法将作为线程执行体并且有返回值。 2创建Callable实现类的实例使用FutureTask类来包装Callable对象该FutureTask对象封装了该Callable对象的call()方法的返回值。 3使用FutureTask对象作为Thread对象的target创建并启动新线程。 4调用FutureTask对象的get()方法来获得子线程执行结束后的返回值 任务 四匹马跑一千米比赛每匹马的速度通过1~10的随机数来产生输出哪匹马是冠军 RunTask1.java代码 import java.util.Random; import java.util.concurrent.Callable;/*** 跑步任务*/public class RunTask1 implements CallableLong {// step/100ms 是否睡着 睡觉时间// 通过方法形参接收参数// 定义属性private int step;private boolean isSleep;private int sleepTime;public RunTask1(int step,boolean isSleep,int sleepTime){this.stepstep;this.isSleepisSleep;this.sleepTimesleepTime;}Overridepublic Long call() throws Exception {int distance0;long start System.currentTimeMillis();while(true){distancestep;if (isSleep) {if (distance 800) { //跑到800米try {System.out.println(Thread.currentThread().getName() 睡 sleepTime ms);Thread.sleep(sleepTime);} catch (InterruptedException e) {e.printStackTrace();}}}if(distance1000){break;}System.out.println(Thread.currentThread().getName() 跑完 distance 米);}try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}return System.currentTimeMillis()-start;} }Test.java代码 import java.util.Random; import java.util.concurrent.FutureTask;public class Test {public static void main(String[] args) throws Exception {//第一匹马的跑步任务RunTask1 horse1new RunTask1(new Random().nextInt(10)1,true,200);FutureTaskLong horseResult new FutureTask(horse1);Thread t1new Thread(horseResult,马1);//第二匹马的跑步任务RunTask1 horse2new RunTask1(new Random().nextInt(10)1,true,400);FutureTaskLong horseResult1 new FutureTask(horse2);Thread t2new Thread(horseResult1,马2);//第三匹马的跑步任务RunTask1 horse3new RunTask1(new Random().nextInt(10)1,true,5500);FutureTaskLong horseResult2 new FutureTask(horse3);Thread t3new Thread(horseResult2,马3);//第四匹马的跑步任务RunTask1 horse4new RunTask1(new Random().nextInt(10)1,false,0);FutureTaskLong horseResult3 new FutureTask(horse4);Thread t4new Thread(horseResult3,马4);t1.start();t2.start();t3.start();t4.start();//统计比赛结果一定要等main线程执行否则 Horse1的线程还没跑完就输出了winner is Horse2if((horseResult.get().longValue() horseResult1.get().longValue()) (horseResult.get().longValue() horseResult2.get().longValue()) (horseResult.get().longValue() horseResult3.get().longValue())){System.out.println(winner is t1.getName());}else if((horseResult1.get().longValue() horseResult.get().longValue()) (horseResult1.get().longValue() horseResult2.get().longValue()) (horseResult1.get().longValue() horseResult3.get().longValue())){System.out.println(winner is t2.getName());}else if((horseResult2.get().longValue() horseResult.get().longValue()) (horseResult2.get().longValue() horseResult1.get().longValue()) (horseResult2.get().longValue() horseResult3.get().longValue())){System.out.println(winner is t3.getName());}else if(horseResult3.get().longValue() horseResult.get().longValue() (horseResult3.get().longValue() horseResult1.get().longValue()) (horseResult3.get().longValue() horseResult2.get().longValue())){System.out.println(winner is t4.getName());}else System.out.println(平局);} }控制台输出想要结果不一样可以通过设置哪一匹马会睡眠从而改变结果代码还是有不足
http://www.hkea.cn/news/14318342/

相关文章:

  • 上海奉贤网站建设 列表网竞价推广课程
  • 魅力网络营销公司网站优化流程图
  • 网站平台运营方案广东营销型网站建设多少钱
  • 教育网站开发需求分析网上黑赌网站如何做代理
  • 百度网站公司信息推广怎么做的媒体门户网站建设方案
  • 用照片做视频的网站2021年电商平台排名
  • 北京建设银行官方网站做网站哪里找程序员
  • 做衣服接订单的网站广告词
  • 网站网页打不开怎么办wordpress让小工具支持简码
  • 河南电商网站开发wordpress文章添加媒体缩略图
  • 芯片商城网站建设网页游戏魔域永恒
  • shopify做国内网站数据库网站建设方案
  • 网站服务公司官网诸暨做网站
  • 品牌购买网站小程序下载
  • 门户网站用什么后台系统好网页游戏传奇世界网页版
  • 安国市城乡建设局网站优化大师免费下载安装
  • 网站制作公司要文化建设费如何注册咨询公司
  • 做网站赚什么钱广州石井做网站
  • 怎么做网址导航网站网络营销策略内容
  • 渝北集团网站建设如何给网站做排名
  • 传智播客php网站开发实例教程深圳网深圳网站开发公司
  • c2c网站有哪些?免费注册com域名
  • 莱芜网站优化加徽信xiala5效果好加强网站技术建设
  • 最权威的网站推广公司山东正元建设网站
  • 个人做网站的流程新版wordpress文章编辑界面
  • 网站怎么注册怎样做金融理财网站
  • phpcms建站流程怀化网站优化推荐
  • 杭州网站建设规划外贸单在哪些网站做
  • 上海市安全建设监理协会网站小城镇建设期刊网站
  • 普陀网站开发培训学校临沂市建设工程监理公司网站