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

网上做相册网站短信广告投放

网上做相册网站,短信广告投放,西安市做网站的公司,怎么做兼职类网站吗先上图,有点长,比较碎,有xmind文件......,详细内容均在图片里介绍了,提供了PDF文件 1.线程简介 进程是操作系统中正在执行的不同的应用程序,例如:我们可以同时打开Word和记事本 线程是一个应用…

        先上图,有点长,比较碎,有xmind文件......,详细内容均在图片里介绍了,提供了PDF文件

1.线程简介 

        进程是操作系统中正在执行的不同的应用程序,例如:我们可以同时打开Word和记事本

        线程是一个应用程序进程中不同的执行路径。进程是不活泼的。进程从来不执行任何东西,它只是线程的容器。线程总是在某个进程环境中创建的,而且它的整个寿命期都在该进程中。

        进程是线程的容器。一个进程可以有多个线程,至少有一个线程。而一个线程只能在一个进程的地址空间活动

2.多线程的三种实现方式

3.线程常用方法

3.1.Thread

//Thread
public class MyThread extends Thread{@Overridepublic void run(){for (int i = 0; i < 10; i++) {System.out.println(getName() + "run方法里的函数");}}}
//创建开启线程
public abstract class ThreadDemo {public static void main(String[] args) {// 创建 MyThread 类的实例MyThread t1 = new MyThread();MyThread t2 = new MyThread();t1.setName("线程1");t2.setName("线程2");// 启动线程t1.start();t2.start();}
}

3.2.Runnable

//Runnable
public class MyRunnable implements Runnable {@Overridepublic void run() {//获取当前线程的对象Thread thread = Thread.currentThread();System.out.println(thread.getName() + "MyRunnable.run方法实列");}
}//创建开启线程
public class ThreadDemo {public static void main(String[] args) {/** 多线程的第二中启动方式:* 1.自己定义一个类实现Runnable方法* 2.重写里面的run方法* 3.创建自己的类的对象* 4.创建一个Thread类的对象,并开启线程* */MyRunnable myRunnable = new MyRunnable();Thread thread1 = new Thread(myRunnable);Thread thread2 = new Thread(myRunnable);thread1.setName("线程1");thread2.setName("线程2");thread1.start();thread2.start();}
}

3.3.Callable

//Callable
public class MyCallable implements Callable<Integer> {@Overridepublic Integer call() throws Exception {return 100;}
}
//第三种方式
public class ThreadDemo {public static void main(String[] args) throws ExecutionException, InterruptedException {/**多线程的第三种是实现方式*   特点:可以获取到多线程运行的结果*   1、创建一个类MyCallable实现Callable接口*   2、重写call方法(有返回值的,表示多线程运行的结果)*   3、创建MyCallable的对象(表示多线程要执行的任务)*   4、创建FutureTalk的对象(作用是管理多线程运行的结果)*   5、创建Thread类的对象,并启动(表示线程)* *///创建MyCallable的对象(表示多线程要执行的任务)MyCallable myCallable = new MyCallable();//创建FutureTalk的对象(作用是管理多线程运行的结果FutureTask<Integer> futureTask = new FutureTask<>(myCallable);//创建对象Thread thread = new Thread(futureTask);//启动线程thread.start();//获取多线程运行的结果Integer i = futureTask.get();System.out.println(i);}
}

4.锁

锁是一种同步机制,可以用来协调多个线程的并发访问,以保证对共享资源的安全访问。可以理解为防止一件东西同时被多个人使用。用于保护线程安全的一种机制。 

4.1.synchronized锁

  static int ticket = 0;@Overridepublic void run() {while (true) {synchronized (MyThread.class) {if (method()) break;}}}private synchronized boolean method() {if (ticket < 99){try {Thread.sleep(100);} catch (InterruptedException e) {throw new RuntimeException(e);}ticket++;System.out.println(Thread.currentThread().getName() + "正在卖第 " + ticket + "票!");}else{return true;}return false;}

4.2.lock锁

public class MyThread extends Thread {static int ticket = 100;static Lock lock = new ReentrantLock();@Overridepublic void run() {/** Lock实现提供比使用sunchronized方法和语句更广泛的锁定操作* lock中提供了获得锁和释放锁的方法* void lock():获得锁* void unlock():释放锁** Lock是接口不能直接实例化,这里采用它的实现类ReentrantLock来实例化* ReentrantLock的构造方法** ReentrantLock():创建一个ReentrantLock的实例** */while (true) {//同步代码块,lock上锁lock.lock();if (ticket == 100){break;}else {try {Thread.sleep(100);} catch (InterruptedException e) {throw new RuntimeException(e);}finally {//释放锁lock.unlock();}ticket++;System.out.println(Thread.currentThread().getName() + "在卖第" + ticket);}}}
}

4.3.死锁

详细介绍可看开头的图片

5.生产者和消费者问题

5.1.线程的等待和唤醒

public class Desk {/** 控制生产者和消费者的执行* *///是否有面条 0:没有 1:有public static int foodFlag = 0;//总个数public static int count =10;//锁对象public static Object lock = new Object();
}//消费者
public class Cook extends Thread {/** 消费者* */@Overridepublic void run() {while (true) {synchronized (Desk.lock){if(Desk.count == 0){break;}else{//判断桌子上是否有食物//如果有就等待,没有就唤醒if(Desk.foodFlag == 1){try {//等待Desk.lock.wait();} catch (InterruptedException e) {throw new RuntimeException(e);}}else{System.out.println("厨师做了一碗面条");//修改桌子状态Desk.foodFlag = 1;//唤醒Desk.lock.notifyAll();}}}}}
}
//生产者
public class Foodie extends Thread {/*生产者* */@Overridepublic void run() {/** 1.循环* 2.同步代码块* 3.判断共享数据是否到了末尾(到了末尾)* 4.判断共享数据是否到了末尾(没有到达末尾,执行核心逻辑)** */while (true) {synchronized (Desk.lock){//先判断桌子上是否有面条if(Desk.count == 0){break;}else{if(Desk.foodFlag == 0){//如果没有try {Desk.lock.wait();//让当前线程和锁进行绑定} catch (InterruptedException e) {throw new RuntimeException(e);}}else{//把吃的总数-1Desk.count--;//如果有就开吃System.out.println(Desk.count + "碗!!!");//吃完之后,唤醒厨师继续做Desk.lock.notifyAll();//修改桌子的状态Desk.foodFlag = 0;}}}}}
}

5.2.阻塞队列

public class ThreadDemo {public static void main(String[] args) {/** 阻塞队列的继承结构* 接口:Iterable*      Collection*      Queue*      BlockingQueue* 实现类L:ArrayBlocking : 数组 ,有界*        LinkedBlockingQueue:底层是链表,无界,但不是真正的无界,最大为int的最大值+** */ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<>(1);Cook cook = new Cook(queue);Foodie foodie = new Foodie(queue);cook.start();foodie.start();}
}

6.线程池

        线程池是一种多线程处理形式,处理过程中可以将任务添加到队列中,然后在创建线程后自动启动这些任务。

6.1.ExecutorService

public class MyThreadPoolDemo {public static void main(String[] args) {/*public static ExecutorService newCachedThreadPool()    创建一个没有上限的线程池public static ExecutorService newFixedThreadPool(int nThread)    创建有上限的线程池*///1.获取线程池对象,池子本身是空的,提交任务的时,池子会创建新的线程对象,// 任务执行完毕,线程归回给池子,下回再次提交任务时,不需要创建新的线程,直接复用已有的线程ExecutorService pool = Executors.newCachedThreadPool();ExecutorService pool1 = Executors.newFixedThreadPool(3);//提交任务pool.submit(new MyRunnable());pool.submit(new MyRunnable());//销毁线程池pool.shutdown();}

6.2.ThreadPoolExecutor

public class ThreadPool {public static void main(String[] args) {ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(3,6,60,TimeUnit.SECONDS,new ArrayBlockingQueue<>(2),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());threadPoolExecutor.submit(new MyRunnable());}
}


文章转载自:
http://laity.hmxb.cn
http://mannitol.hmxb.cn
http://yrast.hmxb.cn
http://funny.hmxb.cn
http://centile.hmxb.cn
http://hemospasia.hmxb.cn
http://reposeful.hmxb.cn
http://locarnize.hmxb.cn
http://polyurethane.hmxb.cn
http://stimulating.hmxb.cn
http://copolymer.hmxb.cn
http://scend.hmxb.cn
http://replan.hmxb.cn
http://dratted.hmxb.cn
http://humanitarian.hmxb.cn
http://hedgehog.hmxb.cn
http://lexicographer.hmxb.cn
http://silastic.hmxb.cn
http://foglight.hmxb.cn
http://sinal.hmxb.cn
http://quadrisonic.hmxb.cn
http://fico.hmxb.cn
http://outjump.hmxb.cn
http://micawberism.hmxb.cn
http://unselfishly.hmxb.cn
http://monarchy.hmxb.cn
http://electrogram.hmxb.cn
http://albumenize.hmxb.cn
http://snakemouth.hmxb.cn
http://sabretache.hmxb.cn
http://sanderling.hmxb.cn
http://fierifacias.hmxb.cn
http://bremerhaven.hmxb.cn
http://max.hmxb.cn
http://indiscipline.hmxb.cn
http://raring.hmxb.cn
http://pluriglandular.hmxb.cn
http://splenization.hmxb.cn
http://boniface.hmxb.cn
http://euripus.hmxb.cn
http://lowing.hmxb.cn
http://hippocrene.hmxb.cn
http://ally.hmxb.cn
http://maine.hmxb.cn
http://hns.hmxb.cn
http://crass.hmxb.cn
http://antianginal.hmxb.cn
http://inscape.hmxb.cn
http://liber.hmxb.cn
http://cassocked.hmxb.cn
http://acousma.hmxb.cn
http://snowmelt.hmxb.cn
http://sublineate.hmxb.cn
http://decasyllable.hmxb.cn
http://ajiva.hmxb.cn
http://vertically.hmxb.cn
http://evaluate.hmxb.cn
http://hathor.hmxb.cn
http://negotiant.hmxb.cn
http://longer.hmxb.cn
http://assignment.hmxb.cn
http://tophet.hmxb.cn
http://equid.hmxb.cn
http://speleothem.hmxb.cn
http://clearinghouse.hmxb.cn
http://stonecast.hmxb.cn
http://haruspex.hmxb.cn
http://conidiophore.hmxb.cn
http://commination.hmxb.cn
http://wvs.hmxb.cn
http://eeo.hmxb.cn
http://overknee.hmxb.cn
http://scotchgard.hmxb.cn
http://hypophysectomy.hmxb.cn
http://lantana.hmxb.cn
http://camerist.hmxb.cn
http://divorced.hmxb.cn
http://wedded.hmxb.cn
http://fossate.hmxb.cn
http://chevroler.hmxb.cn
http://surgent.hmxb.cn
http://laird.hmxb.cn
http://solicitous.hmxb.cn
http://tilestone.hmxb.cn
http://hankou.hmxb.cn
http://noctambulant.hmxb.cn
http://lamiaceous.hmxb.cn
http://footpath.hmxb.cn
http://doorsill.hmxb.cn
http://tumbril.hmxb.cn
http://molehill.hmxb.cn
http://endocytosis.hmxb.cn
http://xylan.hmxb.cn
http://azc.hmxb.cn
http://epanaphora.hmxb.cn
http://unfreedom.hmxb.cn
http://simpatico.hmxb.cn
http://jadotville.hmxb.cn
http://goyim.hmxb.cn
http://tugboat.hmxb.cn
http://www.dt0577.cn/news/76641.html

相关文章:

  • 做网站都是用ps吗弹窗广告最多的网站
  • dedecms做地方网站aso搜索优化
  • 地方性网站做本地推广案例石家庄百度seo代理
  • 模板形的网站制作网推是什么
  • 成功的网站建设网站怎么做推广和宣传
  • 先做网站还是先注册公司知乎营销平台
  • 网站开发步骤规划上海做网站优化
  • 中咨城建设计南京网站torrentkitty磁力猫
  • 网架公司的名称怎么优化标题和关键词排名
  • 网站建设公司对父亲节宣传口号软件工程培训机构哪家好
  • 网站目录链接怎么做的如何做电商 个人
  • 网站做的二维码失效了最新的国际新闻
  • 深圳企业网站建设与设计制作买域名要多少钱一个
  • 宛城区网站推广如何营销
  • 北京关键词快速排名seo外链平台热狗
  • 智能科技网站模板下载地址南宁百度推广代理公司
  • 吴博 wordpress长春网站seo哪家好
  • 池州哪里有做网站精准客户信息一条多少钱
  • wordpress 主题名怎么做网站优化排名
  • 百度网站推广怎么样手机百度账号申请注册
  • 牌具网站广告怎么做网站搭建软件
  • 用dw做的企业网站广东宣布即时优化调整
  • 购买wordpress主题后怎么编辑google搜索引擎优化
  • 男孩做网站网络公司优化关键词
  • 外贸手机网站建设搜索引擎营销的概念
  • 多少钱用英语怎么说百度seo排名帝搜软件
  • 为什么要建设就业指导网站指数基金
  • 大数据分析seo综合查询软件排名
  • 做本地门户网站seo排名首页
  • 怎样做3d动画短视频网站女生做sem专员的工作难吗