JDK 线程池ExecutorsnewCachedThreadPool() //带缓存的 不够时自动添加ExecutorsnewSingleThreadExecutor() //单个线程池 线程死掉后自动创建ExecutorsnewFixedThreadPool() //创建容纳N个线程的ExecutorsnewScheduledThreadPool() //创建定时器线程池
executo() 无返回结果submit() 有返回结果的线程
Callable //可返还结果的线程
ExecutorService threadpol = ExecutorsnewSingleThreadExecutor()Future<String> future = threadpolsubmit(new Callable<String>(){ public String call(){ return aaaa} systemoutprint(Futureget()))
Lock lock = new ReentrantLock() //lock 对象Condition condition = locknewCondition() // 条件 通讯对象conditionawait() //不是 object的 wait conditionsignal() //唤醒
try{ locklock()……
}finally{ lockunLock()}
ReentrantReadWriteLock rwl = ReentrantReadWriteLock() //文件锁rwlreadLock()lock()rwlwriteLock()lock()
条件等待尽量使用while(){
}
多线程关键字ExecutorsnewCachedThreadPool() //带缓存的 不够时自动添加ExecutorsnewSingleThreadExecutor() //单个线程池 死掉后再创建ExecutorsnewFixedThreadPool() //创建容纳N个线程的ExecutorsnewScheduledThreadPool() //创建定时器线程池Lock lock = new ReentrantLock() //lock 互斥锁 对象Condition condition = locknewCondition() // 条件 通讯对象Condition //条件锁Semaphore //信号量 类似执行授权 (最多有个人可以走)
CyclicBarrier //类似集合点 (必须个人同时到才能走)
CountDownLatch //计数器 计时器效果 某时间点同时执行 CountDownLath a = new CountDownLath() aawait() untDown()Exchanger //数据交换 Exchanger a = new Exchanger()//放主线程 aexchange(asd)
ArrayBlockingQueue //阻塞队列 ArrayBlockingQueue 啊 = new ArrayBlockingQueue() aput()//阻塞 aadd() //atack() 获取