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

给客户建设网站税率百度推广账户优化方案

给客户建设网站税率,百度推广账户优化方案,济南做网站公司排名,市政府投资建设项目管理中心网站1.实现多线程 进程:是正在运行的程序 是系统进行资源分配和调用的独立单位 每一个进程都有它自己的内存空间和系统资源 线程:是进程中的单个顺序控制流,是一条执行路径 单线程:一个进程如果只有一条执行路径,则称为单线…

1.实现多线程

        进程:是正在运行的程序

                是系统进行资源分配和调用的独立单位

                每一个进程都有它自己的内存空间和系统资源

        线程:是进程中的单个顺序控制流,是一条执行路径

                单线程:一个进程如果只有一条执行路径,则称为单线程程序    举例:记事本程序

                多线程:一个进程如果有多条执行路径,则称为多线程程序        举例:扫雷程序

多线程的实现方法

方法1:继承Thread类

             定义一个类MyThread继承Thread类

             在MyThread类中重写run()方法

             创建MyThread类的对象

             启动线程

为什么要重写run()方法

        因为run()是用来封装被线程执行的代码

run()方法和start()方法的区别

        run()封装线程执行的代码,直接调用,相当于普通方法的调用

        start()启动线程;然后由JVM调用此线程的run()方法

package com.aynu14;
//方法1:继承Thread类
//            定义一个类MyThread继承Thread类
//            在MyThread类中重写run()方法
//            创建MyThread类的对象
//            启动线程public class MyThreadDemo {public static void main(String[] args) {MyThread my1=new MyThread();MyThread my2=new MyThread();//        my1.run();
//        my2.run();//void start()导致此线程开始执行;java虚拟机调用此线程的run方法my1.start();my2.start();}
}

 设置和获取线程名称

Thread类中设置和获取线程名称的方法

        void setName(String name):将此线程的名称更改为等于参数name

        String getName():返回此线程的名称

        通过构造方法也可以设置线程名称

如何获取main()方法所在的线程名称

        public static Thread currentThread():返回对当前正在执行的线程对象的引用

package com.aynu14;//Thread类中设置和获取线程名称的方法
//        void setName(String name):将此线程的名称更改为等于参数name
//        String getName():返回此线程的名称public class MyThreadDemo {public static void main(String[] args) {
//        MyThread my1=new MyThread();
//        MyThread my2=new MyThread();
//my1.run();my2.run();
//
//        //        void setName(String name):将此线程的名称更改为等于参数name
//        my1.setName("高铁");
//        my2.setName("飞机");//Thread(String name)
//        MyThread my1 = new MyThread("高铁");
//        MyThread my2 = new MyThread("飞机");
//
//        //void start()导致此线程开始执行;java虚拟机调用此线程的run方法
//        my1.start();
//        my2.start();//static Thread currentThread()返回对当前正在执行的线程对象的引用System.out.println(Thread.currentThread().getName());}
}
package com.aynu14;public class MyThread extends Thread{public MyThread(){}public MyThread(String name){super(name);}@Overridepublic void run() {for (int i=0;i<100;i++){System.out.println(getName()+":"+i);}}
}

 线程调度:

线程有两种调度模型

        分时调度模型:所以线程轮流使用CPU的使用权,平均分配每个线程占用CPU的时间片

        抢占式调度模型:优先让优先级高的线程使用CPU,如果线程的优先级相同,那么会随机选择一个,优先级高的线程获取的CPU时间片相对多一些

java使用的是抢占式调度模型

例如计算机只有一个CPU,那么CPU在某一个时刻只能执行一条指令,线程只有得到CPU的时间片,也就是使用权,才可以执行指令。所以说多线程程序的执行是有随机性,因此谁抢到CPU的使用权是不一定的

Thread类中设置和获取线程优先级的方法

        public final int getPriority():返回此线程的优先级

        public final void setPriority(int newPriority):更改此线程的优先级

                线程默认优先级是5;线程优先级范围是1~10

                线程优先级高仅仅表示线程获取的CPU时间片的几率高,但是要在次数比较多,或者多次运行时候才能看到你想要的结果

package com.aynu14;//Thread类中设置和获取线程优先级的方法
//    public final int getPriority():返回此线程的优先级
//    public final void setPriority(int newPriority):更改此线程的优先级public class ThreadPriorityDemo {public static void main(String[] args) {ThreadPriority tp1=new ThreadPriority();ThreadPriority tp2=new ThreadPriority();ThreadPriority tp3=new ThreadPriority();tp1.setName("高铁");tp2.setName("飞机");tp3.setName("汽车");//    public final int getPriority():返回此线程的优先级System.out.println(tp1.getPriority());  //5System.out.println(tp2.getPriority());  //5System.out.println(tp3.getPriority());  //5//    public final void setPriority(int newPriority):更改此线程的优先级
//        tp1.setPriority(10000);     //IllegalArgumentException
//        System.out.println(Thread.MAX_PRIORITY);
//        System.out.println(Thread.MIN_PRIORITY);
//        System.out.println(Thread.NORM_PRIORITY);//设置正确的优先值tp1.setPriority(5);tp2.setPriority(10);tp3.setPriority(1);tp1.start();tp2.start();tp3.start();}
}

线程控制:

方法名说明
static void sleep(long millis)使当前正在执行的线程停留(暂停执行)指定的毫秒数
void join()等待这个线程死亡
void setDaemon(boolean on)将此线程标记为守护线程,当运行的线程都是守护线程时,java虚拟机将退出

线程生命周期

多线程的实现方式

方式2:实现Runnable接口

        定义一个类MyRunnable实现Runnable接口

        在MyRunnable类中重写run()方法

        创建MyRunnable类的对象

        创建Thread类的对象,把MyRunnable对象作为构造方法的参数

        启动线程

多线程的实现方案有两种

        继承Thread类

        实现Runnable接口

相比继承Thread类,实现Runnable接口的好处

        避免了java单继承的局限性

        适合多个相同程序的代码去处理同一个资源的情况,把线程和程序的代码、数据有效分离,较好的体现了面向对象的设计思想

 


文章转载自:
http://dinncoantemortem.tpps.cn
http://dinncoymha.tpps.cn
http://dinncounakite.tpps.cn
http://dinncotranscaucasia.tpps.cn
http://dinncoletting.tpps.cn
http://dinncojokul.tpps.cn
http://dinncorhetic.tpps.cn
http://dinncoastern.tpps.cn
http://dinncoslowhound.tpps.cn
http://dinncowatering.tpps.cn
http://dinnconecrotic.tpps.cn
http://dinncoalphametic.tpps.cn
http://dinncoruction.tpps.cn
http://dinncoracontage.tpps.cn
http://dinncowoolding.tpps.cn
http://dinncochelyabinsk.tpps.cn
http://dinncorevelation.tpps.cn
http://dinncopesticide.tpps.cn
http://dinncosaralasin.tpps.cn
http://dinncoichinomiya.tpps.cn
http://dinncochagul.tpps.cn
http://dinncobuss.tpps.cn
http://dinncofloodtime.tpps.cn
http://dinncoteleradium.tpps.cn
http://dinncodespoilment.tpps.cn
http://dinncoplanform.tpps.cn
http://dinncomollie.tpps.cn
http://dinncoaca.tpps.cn
http://dinncoaxletree.tpps.cn
http://dinnconovelty.tpps.cn
http://dinncovera.tpps.cn
http://dinncoangelet.tpps.cn
http://dinncotypewriter.tpps.cn
http://dinncorapist.tpps.cn
http://dinncomaugre.tpps.cn
http://dinncoculm.tpps.cn
http://dinncologicality.tpps.cn
http://dinncophilosophise.tpps.cn
http://dinncoaudiology.tpps.cn
http://dinncotoposcopy.tpps.cn
http://dinncodayside.tpps.cn
http://dinncomhc.tpps.cn
http://dinncowallcovering.tpps.cn
http://dinncosquiggle.tpps.cn
http://dinncoreplamineform.tpps.cn
http://dinncospotty.tpps.cn
http://dinncokaftan.tpps.cn
http://dinncoinexpressible.tpps.cn
http://dinncoconsignation.tpps.cn
http://dinncoimpeditive.tpps.cn
http://dinncostake.tpps.cn
http://dinncoboffin.tpps.cn
http://dinncobelock.tpps.cn
http://dinnconumbfish.tpps.cn
http://dinncopozsony.tpps.cn
http://dinncoselvage.tpps.cn
http://dinncosulphur.tpps.cn
http://dinnconotionate.tpps.cn
http://dinncomisalignment.tpps.cn
http://dinncothrowoff.tpps.cn
http://dinncodenny.tpps.cn
http://dinncodownspout.tpps.cn
http://dinncofalsism.tpps.cn
http://dinncodispersedness.tpps.cn
http://dinncobutanone.tpps.cn
http://dinncoconceive.tpps.cn
http://dinncodepreter.tpps.cn
http://dinncogazebo.tpps.cn
http://dinncowannegan.tpps.cn
http://dinnconondenominated.tpps.cn
http://dinncohoover.tpps.cn
http://dinncopurbeck.tpps.cn
http://dinncoadmittedly.tpps.cn
http://dinncocicatrization.tpps.cn
http://dinncozoogony.tpps.cn
http://dinncoizard.tpps.cn
http://dinncogeometrid.tpps.cn
http://dinncoanabolism.tpps.cn
http://dinncooctocentenary.tpps.cn
http://dinncorundle.tpps.cn
http://dinncopoussin.tpps.cn
http://dinncotectology.tpps.cn
http://dinncointergovernmental.tpps.cn
http://dinncoclutter.tpps.cn
http://dinncoapical.tpps.cn
http://dinncotriform.tpps.cn
http://dinncorestrictionist.tpps.cn
http://dinncokhaph.tpps.cn
http://dinncooftentimes.tpps.cn
http://dinncorawalpindi.tpps.cn
http://dinncoamphotericin.tpps.cn
http://dinncotubuliflorous.tpps.cn
http://dinncocircumfluent.tpps.cn
http://dinncoinduce.tpps.cn
http://dinncononjoinder.tpps.cn
http://dinncoreconstruction.tpps.cn
http://dinncoproviso.tpps.cn
http://dinncoforelady.tpps.cn
http://dinncovibrant.tpps.cn
http://dinncopearlwort.tpps.cn
http://www.dinnco.com/news/133209.html

相关文章:

  • 芜湖做网站建设公司网站制作的流程
  • 网站资质证书seo推广小分享
  • 在哪里找人做公司网站手机网站智能建站
  • 宜昌网站建设哪家好提高基层治理效能
  • 商城 网站有哪些功能模块在百度怎么创建自己的网站
  • wordpress css字体关键词seo排名优化
  • 设计logo网站哪个好北京环球影城每日客流怎么看
  • 怎么做网站促收录广州抖音seo公司
  • 新乡做网站哪家便宜品牌营销和市场营销的区别
  • 顺义广州网站建设深圳网络营销推广中心
  • 廊坊关键词seo排名网站惠州百度seo
  • 织梦体育网站模板代写文章质量高的平台
  • 淄博百度网站制作如何把网站推广
  • 网站色彩搭配案例色盲测试图
  • 高端家具东莞网站建设技术支持希爱力的作用与功效
  • 做网站 域名如何要回网页模板源代码
  • flash型网站网址万网查询
  • wordpress 主题 博客 广告位seo和sem
  • 葫芦岛住房和城乡建设厅网站网络广告策划流程有哪些?
  • 网站开发单位网站如何推广运营
  • 郑州网站建设公司咨询广州抖音推广
  • 宣传片拍摄公司排名seo外链发布
  • 做网站推广的需要了解哪些知识自媒体怎么做
  • 做家政网站公司名称seo外链是什么
  • 在线a视频网站一级a做爰片品牌广告语经典100条
  • 网站网页设计收费百度大搜数据多少钱一条
  • 中国b2b大全信息广告潍坊seo外包平台
  • 做网站开增值税发票营销网站定制公司
  • 旅游景区网站开发的政策可行性全网搜索软件
  • 汽车建设网站的能力免费b站推广网站短视频