线程
x_l_x
人生为棋,我愿为卒.
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
线程实现Runnable接口
package com.lxxu.testthread;import java.util.concurrent.Callable;import java.util.concurrent.FutureTask;class MyThread5 implements Callable<String>{// 线程的主体类 @Override public String ca...原创 2018-11-29 08:33:30 · 146 阅读 · 0 评论 -
生产者消费者
package com.lxxu.testthread;class Message{ private String title; private String content; private boolean flag = true;//表示生产或消费形式 //flag = ture 表示允许生产,不许消费 //flag = flase 表示允许消费,不许生产 public sy...原创 2018-12-06 10:30:04 · 127 阅读 · 0 评论 -
线程加减法案例
package com.lxxu.testthread;class AddThread implements Runnable{ private Resource resource; public AddThread(Resource resource) { this.resource = resource; } @Override public void run() { f...原创 2018-12-08 13:41:32 · 279 阅读 · 1 评论 -
线程休眠中断
package com.lxxu.testthread;public class ThreadDemo9 { /** * * @throws InterruptedException */ public static void main(String[] args) throws Exception { Thread thread = new Thread(() -&g...原创 2018-12-01 09:49:26 · 271 阅读 · 0 评论 -
线程强制运行、礼让、优先级
线程强制运行:Thread.join();线程礼让: Thread.yieId();优先级: public final void setPriority(int new Priority); public final int getPriority();最高优先级:public static final int MAX_PRIORITY、10中等...原创 2018-12-03 08:21:48 · 328 阅读 · 0 评论 -
线程
class MyThread extends Thread{//线程的主体类 private String title; public MyThread(String title){ this.title = title; } @Override public void run(){//线程的主体方法 for(int i = 0; i < 10; i++){ ...原创 2018-11-26 08:35:19 · 123 阅读 · 0 评论 -
多线程引用Lameda函数表达式
package com.lxxu.testthread;class MyThread3 implements Runnable{//线程的主体类 private String title; public MyThread3(String title){ this.title = title; } @Override public void run(){//线程的主体方法...原创 2018-11-27 08:54:27 · 238 阅读 · 0 评论 -
多线程实现Runnable接口
package com.lxxu.testthread;class MyThread2 implements Runnable{//线程的主体类 private String title; public MyThread2(String title){ this.title = title; } @Override public void run(){//线程的主体方法...原创 2018-11-27 08:50:33 · 174 阅读 · 0 评论 -
线程休眠
package com.lxxu.testthread;public class ThreadDemo8{ /** * 线程休眠 * 由于线程执行是有先后的,线程休眠是并不是同时进行的 */ public static void main(String[] args){ Runnable run = ()->{ for(int i=0;i<10;i++)...原创 2018-11-30 08:52:33 · 426 阅读 · 0 评论 -
主线程子线程
package com.lxxu.testthread;public class ThreadDemo7{ public static void main(String[] args){ System.out.println("任务一"); System.out.println("任务二"); new Thread(()->{//子线程 int temp = 0;...原创 2018-11-30 08:22:59 · 204 阅读 · 0 评论 -
获取当前线程名称
package com.lxxu.testthread;class MyThread6 implements Runnable{//线程的主体类 @Override public void run(){//线程的主体方法 System.out.println(Thread.currentThread().getName()); }}public class Thre...原创 2018-11-30 08:13:23 · 1915 阅读 · 0 评论 -
volatile与synchronized
volatile主要在属性上使用,synchronized主要在代码块或方法上使用volatile无法描述线程同步的处理,他是一种直接内存的处理,避免了副本的操作,而synchronized是处理同步的。...原创 2018-12-07 09:36:43 · 121 阅读 · 0 评论
分享