随笔分类 -  多线程

摘要:创建线程方法1、 class mythread extends Thread{ 重写run方法 } mythread m=new mythread () 启动:m.start() 创建线程方法2、 class mythread implements Runnable{ 重写run方法 } mythread m=new mythread () Thread t=new Th... 阅读全文
posted @ 2019-07-03 09:32 黑魔法os 阅读(1151) 评论(0) 推荐(0)
摘要:可见性 一个线程对共享变量的修改 能够被其他线程看到 共享数据的访问权限都必须定义为private —————————————————————————————————————— ---工作内存1(拷贝x的副本)--线程1 主内存(共享变量x存放) ---工作内存2(拷贝x的副本)--线程2 —————————————————————————————————————— sync... 阅读全文
posted @ 2019-07-03 09:27 黑魔法os 阅读(517) 评论(0) 推荐(0)
摘要:1)SingleThreadExecutor:单个后台线程 (其缓冲队列是无界的) public static ExecutorService newSingleThreadExecutor() { return new FinalizableDelegatedExecutorService ( new ThreadPoolExecutor(1, 1, ... 阅读全文
posted @ 2019-07-03 09:26 黑魔法os 阅读(142) 评论(0) 推荐(0)
摘要:(1)Callable接口更像是Runnable接口的增强版,相比较Runable接口,Call()方法新增捕获和抛出异常的功能;Call()方法可以返回值 (2)Future接口提供了一个实现类FutureTask实现类,FutureTaks类用来保存Call()方法的返回值,并作为Thread类的target。 (3)调用FutureTask的get()方法来获取返回值 import j... 阅读全文
posted @ 2019-07-03 09:23 黑魔法os 阅读(2861) 评论(0) 推荐(0)