1,线程状态转换

无限期等待:

限期等待:

线程生命流程:

2,实现方式

代码实现样例【三种方式】:

packagecom.cnblogs.mufasa.demo2;importjava.util.concurrent.Callable;public class test1_Runnable implementsRunnable{

@Overridepublic voidrun() {for(int i=0;i<50;i++){

System.out.println("当前线程:"+i);

}

}

}class test2_Callable implements Callable{private intnum;publictest2_Callable(){}public test2_Callable(intnum){this.num=num;

}

@Overridepublic String call() throwsException {for(int i=0;i<50;i++){

System.out.println(this.num+"线程:"+i);

}return num+"线程已完成";

}

}class test3_Thread extendsThread {private intnum;publictest3_Thread(){}public test3_Thread(intnum){this.num=num;

}

@Overridepublic voidrun() {for(int i=0;i<50;i++){

System.out.println(this.num+"线程:"+i);

}

}

}

View Code

packagecom.cnblogs.mufasa.demo2;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.FutureTask;public classClient {public static void main(String[] args) throwsExecutionException, InterruptedException {//实现 Runnable 接口//test1_Runnable instance=new test1_Runnable();//Thread thread=new Thread(instance);//Thread thread1=new Thread(instance);//thread.start();//thread1.start();//实现 Callable 接口//test2_Callable instance=new test2_Callable(1);//FutureTask ft=new FutureTask<>(instance);//Thread thread = new Thread(ft);//test2_Callable instance1=new test2_Callable(2);//FutureTask ft2=new FutureTask<>(instance1);//Thread thread1 = new Thread(ft2);//

//thread.start();//thread1.start();//System.out.println(ft.get());//System.out.println(ft2.get());//继承 Thread 类

test3_Thread thread1=new test3_Thread(1);

test3_Thread thread2=new test3_Thread(2);

thread1.start();

thread2.start();

}

}

View Code

3,基础线程机制

代码实现样例:

package com.cnblogs.mufasa.demo3;public classClient1 {public static voidmain(String[] args) throws InterruptedException {//设置守护线程 setDaemon 伴随线程而运行//Thread thread1 = new Thread(new test1_Runnable(1));//Thread thread2 = new Thread(new test3_Thread(2));//thread1.setDaemon(true);//thread1.start();//thread2.start();//sleep Thread.sleep(millisec) 方法会休眠当前正在执行的线程,millisec 单位为毫秒//sleep() 可能会抛出 InterruptedException,因为异常不能跨线程传播回 main() 中,因此必须在本地进行处理//Thread thread1 = new Thread(()->{//try {//System.out.println("延迟2s");//Thread.sleep(2000);//System.out.println("延迟结束");//} catch (InterruptedException e) {//e.printStackTrace();//}//});//thread1.start();//new Thread(new Runnable() {//@Override//public void run() {//System.out.println("延迟2s");//try {//Thread.sleep(2000);//System.out.println("延迟结束");//Thread.yield();//可以让出资源//Thread.sleep(2000);//} catch (InterruptedException e) {//e.printStackTrace();//}finally {//System.out.println("线程1运行结束");//}//}//}).start();//

//new Thread(()->{//try {//Thread.sleep(2000);//} catch (InterruptedException e) {//e.printStackTrace();//}finally {//System.out.println("线程2延迟结束");//}//}).start();

Thread t= new Thread(newRunnable(){public voidrun(){

System.out.println("First task started");

System.out.println("Sleeping for 2 seconds");try{

Thread.sleep(2000);

}catch(InterruptedException e){

e.printStackTrace();

}

System.out.println("First task completed");

}

});

Thread t1= new Thread(newRunnable(){public voidrun(){

System.out.println("Second task completed");

}

});//在t执行完毕后t1执行

t.start(); //Line 15

t.join(); //Line 16

t1.start();

}

}

View Code

4,中断

packagecom.cnblogs.mufasa.demo4;importjava.util.concurrent.Executor;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;importjava.util.concurrent.Future;import staticjava.lang.Thread.interrupted;class InterruptExample extendsThread {

@Overridepublic voidrun() {

System.out.println("sleep 2s");try{

Thread.sleep(2000);

System.out.println("Thread run");

}catch(InterruptedException e) {

System.out.println("休眠中断");

e.printStackTrace();

}

}

}class InterruptExample1 extendsThread {

@Overridepublic voidrun() {while (!interrupted()) {//..

}

System.out.println("Thread end");

}

}public classClient {public static voidmain(String[] args) {//InterruptExample thread1 = new InterruptExample();//thread1.start();//thread1.interrupt();//System.out.println("Main run");//InterruptExample1 thread2 = new InterruptExample1();//thread2.start();//thread2.interrupt();//ExecutorService executorService = Executors.newCachedThreadPool();//executorService.execute(() -> {//try {//Thread.sleep(2000);//System.out.println("Thread run");//} catch (InterruptedException e) {//System.out.println("线程程序池全体中断");//e.printStackTrace();//}//});//executorService.shutdownNow();//System.out.println("Main run");

ExecutorService executorService=Executors.newCachedThreadPool();

Future> future=executorService.submit(()->{

System.out.println("3");while (!interrupted()){

System.out.println("2");

}

System.out.println("1");

});

future.cancel(true);//强制中断

}

}

View Code

5,互斥同步

代码实现:

packagecom.cnblogs.mufasa.demo5;importjava.util.concurrent.Executor;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;importjava.util.concurrent.locks.Lock;importjava.util.concurrent.locks.ReentrantLock;class SynchronizedExample {//同步代码块,作用于同一个对象

public voidfunc1() {synchronized (this) {for (int i = 0; i < 10; i++) {

System.out.print(i+ " ");

}

}

}

}class SynchronizedExample1 {//同步方法,作用于同一个对象

public synchronized voidfunc1() {for (int i = 0; i < 10; i++) {

System.out.print(i+ " ");

}

}

}class SynchronizedExample2 {//同步类,作用于整个类。

public voidfunc1() {synchronized(SynchronizedExample2.class){for (int i = 0; i < 10; i++) {

System.out.print(i+ " ");

}

}

}

}class SynchronizedExample3 {//同步静态方法,作用于整个类。

public static synchronized voidfunc1() {for (int i = 0; i < 10; i++) {

System.out.print(i+ " ");

}

}

}class LockExample {//ReentrantLock 是 java.util.concurrent(J.U.C)包中的锁。

private Lock lock=newReentrantLock();public voidfunc() {

lock.lock();try{for (int i = 0; i < 10; i++) {

System.out.print(i+ " ");

}

}finally{

lock.unlock();//确保解锁,防止死锁

}

}

}public classClient {public static voidmain(String[] args) {//synchronized-代码块 相同对象-同步代码块//SynchronizedExample e1=new SynchronizedExample();//ExecutorService executorService= Executors.newCachedThreadPool();//executorService.execute(()->e1.func1());//executorService.execute(()->e1.func1());//synchronized-代码块 不同对象-同步代码块,没有同步!!!//SynchronizedExample e1 = new SynchronizedExample();//SynchronizedExample e2 = new SynchronizedExample();//ExecutorService executorService = Executors.newCachedThreadPool();//executorService.execute(()->e1.func1());//executorService.execute(()->e2.func1());//synchronized-方法 不同对象,没有同步!!!//SynchronizedExample1 e1 = new SynchronizedExample1();//SynchronizedExample1 e2 = new SynchronizedExample1();//ExecutorService executorService = Executors.newCachedThreadPool();//executorService.execute(()->e1.func1());//executorService.execute(()->e2.func1());//synchronized-类 不同对象,有同步//SynchronizedExample2 e1 = new SynchronizedExample2();//SynchronizedExample2 e2 = new SynchronizedExample2();//ExecutorService executorService = Executors.newCachedThreadPool();//executorService.execute(()->e1.func1());//executorService.execute(()->e2.func1());//synchronized-静态方法 不同对象,有同步//SynchronizedExample3 e1 = new SynchronizedExample3();//SynchronizedExample3 e2 = new SynchronizedExample3();//ExecutorService executorService = Executors.newCachedThreadPool();//executorService.execute(()->e1.func1());//executorService.execute(()->e2.func1());//JDK实现的锁,作用一个对象

LockExample lockExample = newLockExample();

LockExample lockExample1= newLockExample();

ExecutorService executorService=Executors.newCachedThreadPool();

executorService.execute(()->lockExample.func());//executorService.execute(() -> lockExample1.func());

executorService.execute(() ->lockExample.func());

}

}

View Code

6,线程协作

样例代码:

packagecom.cnblogs.mufasa.demo6;importjava.util.concurrent.Executor;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;importjava.util.concurrent.locks.Condition;importjava.util.concurrent.locks.Lock;importjava.util.concurrent.locks.ReentrantLock;classJoinExample{private class A extendsThread{

@Overridepublic voidrun(){for(int i=0;i<10;i++){

System.out.println("A:"+i);

}

}

}private class B extendsThread {privateA a;

B(A a) {this.a =a;

}

@Overridepublic voidrun() {try{

a.join();//先完成A线程,继续B线程

} catch(InterruptedException e) {

e.printStackTrace();

}

System.out.println("B");

}

}public voidtest() {

A a= newA();

B b= newB(a);

b.start();

a.start();

}

}classWaitNotifyExample{public synchronized voidbefore(){

System.out.println("before");

notifyAll();//通知等待的线程

}public synchronized voidafter(){try{

wait();//先进行等待

} catch(InterruptedException e) {

e.printStackTrace();

}for(int i=0;i<10;i++){

System.out.print(i);

}

System.out.println("after");

}

}classAwaitSingalExample{private Lock lock=newReentrantLock();private Condition condition=lock.newCondition();public voidbefore(){

lock.lock();try{

System.out.println("before");

condition.signalAll();

}finally{

lock.unlock();

}

}public voidafter(){

lock.lock();try{

condition.await();

System.out.println("after");

}catch(InterruptedException e) {

e.printStackTrace();

}finally{

lock.unlock();

}

}

}public classClient {public static voidmain(String[] args) {//JoinExample example=new JoinExample();//example.test();//ExecutorService executorService = Executors.newCachedThreadPool();//WaitNotifyExample example = new WaitNotifyExample();//WaitNotifyExample example1 = new WaitNotifyExample();//executorService.execute(() -> example.after());//executorService.execute(() -> example1.after());//executorService.execute(() -> example.before());//executorService.execute(() -> example1.before());

ExecutorService executorService=Executors.newCachedThreadPool();

AwaitSingalExample example=newAwaitSingalExample();

executorService.execute(()->example.after());

executorService.execute(()->example.before());

}

}

View Code

7,J.U.C-AQS【java.util.concurrent】

样例代码:

packagecom.cnblogs.mufasa.demo7;import java.util.concurrent.*;classCyclicBarrier {private intparties;private intcount;privateRunnable barrierCommand;public CyclicBarrier(intparties,Runnable barrierAction){if (parties <= 0) throw newIllegalArgumentException();this.parties =parties;this.count =parties;this.barrierCommand =barrierAction;

}public CyclicBarrier(intparties) {this(parties, null);

}

}public classClient {public static void main(String[] args) throwsInterruptedException {final int clientCount=5;final int totalRequestCount=10;

Semaphore semaphore=newSemaphore(clientCount);

ExecutorService executorService=Executors.newCachedThreadPool();for(int i=0;i

executorService.execute(()->{try{

semaphore.acquire();

System.out.print(semaphore.availablePermits()+" ");

}catch(InterruptedException e) {

e.printStackTrace();

}finally{

semaphore.release();

}

});

}

executorService.shutdown();//Semaphore//final int totalThread =10;//CyclicBarrier cyclicBarrier=new CyclicBarrier(totalThread);//ExecutorService executorService=Executors.newCachedThreadPool();//for(int i=0;i{//System.out.println("before...");//try{//cyclicBarrier.wait();//源程序是await,这里只能使用wait//} catch (InterruptedException e) {//e.printStackTrace();//}//System.out.print("after..");//});//executorService.shutdown();//}//CountDownLatch实例//final int totalThread=10;//CountDownLatch countDownLatch=new CountDownLatch(3);//ExecutorService executorService= Executors.newCachedThreadPool();//for(int i=0;i<6;i++){//int finalI = i;//Thread.sleep(1000);//executorService.execute(()->{//System.out.print(finalI +"run-");//countDownLatch.countDown();//});//}//new Thread(()->{//try {//countDownLatch.await();//} catch (InterruptedException e) {//e.printStackTrace();//}//System.out.println("await等待线程");//}).start();//

//System.out.println("end");//executorService.shutdown();

}

}

View Code

packagecom.cnblogs.mufasa.demo7;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;importjava.util.concurrent.Semaphore;public classSemaphoreExample {public static voidmain(String[] args) {final int clientCount = 3;final int totalRequestCount = 10;

Semaphore semaphore= newSemaphore(clientCount);

ExecutorService executorService=Executors.newCachedThreadPool();for (int i = 0; i < totalRequestCount; i++) {

executorService.execute(()->{try{

semaphore.acquire();

System.out.print(semaphore.availablePermits()+ " ");

}catch(InterruptedException e) {

e.printStackTrace();

}finally{

semaphore.release();

}

});

}

executorService.shutdown();

}

}

View Code

8.J.U.C-其他组件

样例代码:

packagecom.cnblogs.mufasa.demo8;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.ForkJoinPool;importjava.util.concurrent.Future;importjava.util.concurrent.RecursiveTask;public class ForkJoinExample extends RecursiveTask{private final int threshold=5;private intfirst;private intlast;public ForkJoinExample(int first,intlast){this.first=first;this.last=last;

}

@OverrideprotectedInteger compute() {int result=0;if(last-first<=threshold){//运算量足够小直接计算

for(int i=first;i<=last;i++){

result+=i;

}

}else{//拆分成小任务

int middle=first+(last-first)/2;

ForkJoinExample leftTask=newForkJoinExample(first,middle);

ForkJoinExample rightTask=new ForkJoinExample(middle+1,last);

leftTask.fork();

rightTask.fork();

result=leftTask.join()+rightTask.join();

}returnresult;

}public static int sum(int first,intlast){int sum=0;for(int i=first;i<=last;i++){

sum+=i;

}returnsum;

}public static void main(String[] args) throwsExecutionException, InterruptedException {//普通方法计算//System.out.println(sum(1, 1000000000));//并行计算方法//ForkJoinExample example = new ForkJoinExample(1, 1000000000);//ForkJoinPool forkJoinPool = new ForkJoinPool();//Future result=forkJoinPool.submit(example);//System.out.println(result.get());

}

}

View Code

packagecom.cnblogs.mufasa.demo8;importjava.util.concurrent.Callable;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.Future;importjava.util.concurrent.FutureTask;public classFutureTaskExample{public static void main(String[] args) throwsExecutionException, InterruptedException {

FutureTask futureTask=new FutureTask<>(new Callable() {

@Overridepublic Integer call() throwsException {int result=0;for(int i=0;i<10;i++){

Thread.sleep(500);

System.out.println("thread-A:"+i);

result+=i;

}returnresult;

}

});

Thread computeThread=newThread(futureTask);

computeThread.start();

Thread otherThread=new Thread(()->{

System.out.println("other task is running...");try{

Thread.sleep(1000);

}catch(InterruptedException e) {

e.printStackTrace();

}

});

otherThread.start();

System.out.println("运行正常");

System.out.println(futureTask.get());

}

}

View Code

packagecom.cnblogs.mufasa.demo8;importjava.util.concurrent.ArrayBlockingQueue;importjava.util.concurrent.BlockingQueue;public classProducerConsumer {private static BlockingQueue queue=new ArrayBlockingQueue<>(5);private static class Producer extendsThread{

@Overridepublic voidrun() {try{

queue.put("product");

}catch(InterruptedException e) {

e.printStackTrace();

}

System.out.println(queue.size()+"produce..");

}

}private static class Consumer extendsThread{

@Overridepublic voidrun() {try{

String product=queue.take();

}catch(InterruptedException e) {

e.printStackTrace();

}

System.out.println(queue.size()+"consume..");

}

}public static void main(String[] args) {//类似缓存,协调速率

for(int i=0;i<2;i++){

Producer producer=newProducer();

producer.start();

}for(int i=0;i<5;i++){

Consumer consumer=newConsumer();

consumer.start();

}for (int i = 0; i < 3; i++) {

Producer producer= newProducer();

producer.start();

}

}

}

View Code

9.线程不安全

packagecom.cnblogs.mufasa.demo9;importjava.util.concurrent.CountDownLatch;importjava.util.concurrent.Executor;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;classThreadUnsafeExample{private int cnt=0;//public synchronized void add(){//输出为1000,同步后输出正常

public void add(){//不同步后,输出不正常

cnt++;

}public intget(){returncnt;

}

}public classClient {public static void main(String[] args) throwsInterruptedException {final int threadSize=1000;

ThreadUnsafeExample example=newThreadUnsafeExample();final CountDownLatch countDownLatch=newCountDownLatch(threadSize);

ExecutorService executorService=Executors.newCachedThreadPool();for(int i=0;i

executorService.execute(()->{

example.add();

countDownLatch.countDown();

});

}

countDownLatch.await();

executorService.shutdown();

System.out.println(example.get());

}

}

View Code

10.Java内存模式

packagecom.cnblogs.mufasa.demo10;importjava.util.concurrent.CountDownLatch;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;importjava.util.concurrent.atomic.AtomicInteger;public classAtomicExample {private AtomicInteger cnt=newAtomicInteger();public voidadd(){

cnt.incrementAndGet();//原子自增

}public intget(){returncnt.get();

}public static void main(String[] args) throwsInterruptedException {final int threadSize=1000;

AtomicExample example=newAtomicExample();final CountDownLatch countDownLatch=newCountDownLatch(threadSize);

ExecutorService excutorService=Executors.newCachedThreadPool();for(int i=0;i

excutorService.execute(()->{

example.add();

countDownLatch.countDown();

});

}

countDownLatch.await();

excutorService.shutdown();

System.out.println(example.get());

}

}

View Code

packagecom.cnblogs.mufasa.demo10;importjava.util.concurrent.CountDownLatch;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;public classAtomicSynchronizedExample {private int cnt=0;public synchronized voidadd(){

cnt++;

}public synchronized intget(){returncnt;

}public static void main(String[] args) throwsInterruptedException {final int threadSize = 1000;

AtomicSynchronizedExample example=newAtomicSynchronizedExample();final CountDownLatch countDownLatch = newCountDownLatch(threadSize);

ExecutorService executorService=Executors.newCachedThreadPool();for(int i=0;i

executorService.execute(()->{

example.add();

countDownLatch.countDown();

});

}

countDownLatch.await();

executorService.shutdown();

System.out.println(example.get());

}

}

View Code

11.线程安全

packagecom.cnblogs.mufasa.demo11;importjava.util.concurrent.Executor;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;importjava.util.concurrent.atomic.AtomicInteger;public classAtomicIntegerExample {private AtomicInteger cnt=newAtomicInteger();public voidadd(){

cnt.incrementAndGet();

}public intget(){returncnt.get();

}public static void main(String[] args) throwsInterruptedException {

AtomicIntegerExample example=newAtomicIntegerExample();

ExecutorService executorService=Executors.newCachedThreadPool();for(int i=0;i<10;i++){

executorService.execute(()->example.add());

}

Thread.sleep(100);

example.add();

System.out.println(example.get());

executorService.shutdown();

}

}

View Code

packagecom.cnblogs.mufasa.demo11;importjava.util.Collections;importjava.util.HashMap;importjava.util.Map;public classImmutableExample {public static voidmain(String[] args) {

Map map=new HashMap<>();

map.put("b",2);

System.out.println(map.get("b"));

Map unmodifiableMap= Collections.unmodifiableMap(map);//相当于设置一下

System.out.println(unmodifiableMap.get("b"));

unmodifiableMap.put("a",1);

}

}

View Code

packagecom.cnblogs.mufasa.demo11;importjava.util.concurrent.Executor;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;public classStack_closedExample {public voidadd100() {int cnt=0;for(int i=0;i<100;i++){

cnt++;

}

System.out.println(cnt);

}public static voidmain(String[] args) {

Stack_closedExample example=newStack_closedExample();

ExecutorService executorService=Executors.newCachedThreadPool();

executorService.execute(()->example.add100());

executorService.execute(()->example.add100());

executorService.shutdown();

}

}

View Code

packagecom.cnblogs.mufasa.demo11;public classThreadLocalExample {public static voidmain(String[] args) {

ThreadLocal threadLocal=newThreadLocal();

Thread thread1=new Thread(()->{

threadLocal.set(1);try{

Thread.sleep(1000);

}catch(InterruptedException e) {

e.printStackTrace();

}

System.out.println(threadLocal.get());

threadLocal.remove();

});

Thread thread2=new Thread(()->{

threadLocal.set(2);

threadLocal.remove();

});

thread1.start();

thread2.start();

}

}

View Code

packagecom.cnblogs.mufasa.demo11;public classThreadLocalExample1 {public static voidmain(String[] args) {

ThreadLocal threadLocal1=newThreadLocal();

ThreadLocal threadLocal2=newThreadLocal();

Thread thread1= new Thread(() ->{

threadLocal1.set(1);

threadLocal2.set(1);

});

Thread thread2= new Thread(() ->{

threadLocal1.set(2);

threadLocal2.set(2);

});

thread1.start();

thread2.start();

}

}

View Code

12.锁优化

packagecom.cnblogs.mufasa.demo12;public classStringExample {public staticString concatString(String s1, String s2, String s3) {return s1 + s2 +s3;

}public staticString concatString1(String s1, String s2, String s3) {

StringBuilder sb= newStringBuilder ();

sb.append(s1);

sb.append(s2);

sb.append(s3);returnsb.toString();

}public static voidmain(String[] args) {

System.out.println(concatString("12","34","56"));

System.out.println(concatString1("12","34","56"));

}

}

View Code

13.多线程开发良好的实践

java实现思维导图_Java并发(思维导图)相关推荐

  1. java 随机生成图_java – 如何生成随机图?

    我希望能够在 Java中生成随机,无向和连接的图形.另外,我希望能够控制图中的最大顶点数.我不确定解决这个问题的最佳方法是什么,但这里有一些我能想到的: (1)生成一个介于0和n之间的数字,并将其作为 ...

  2. java 甘特图_Java报表软件--甘特图(Gantt chart)深度解析

    什么是甘特图(Gantt chart) 一般对甘特图的解释是:以图示的方式通过活动列表和时间刻度形象地表示出任何特定项目的活动顺序与持续时间,即甘特图(Gantt chart)是将活动与时间联系起来的 ...

  3. java集合类继承关系图_java集合继承关系图

    面向对象语言对事物的体现都是以对象的形式,所以为了方便对多个对象的操作,就对对象进行存储,集合就是存储对象最常用的一种方式. 数组虽然也可以存储对象,但长度是固定的:集合长度是可变的,数组中可以存储基 ...

  4. java 切图_java用pdfbox切图并重绘宽高

    引入pdfbox使用的jar pdfbox-2.0.8.jar,maven依赖如图: org.apache.pdfbox pdfbox 2.0.8 切图:按页切图并生成对应的png格式的图片,输出至相 ...

  5. java 线程安全的原因_Java并发编程——线程安全性深层原因

    线程安全性深层原因 这里我们将会从计算机硬件和编辑器等方面来详细了解线程安全产生的深层原因. 缓存一致性问题 CPU内存架构 随着CPU的发展,而因为CPU的速度和内存速度不匹配的问题(CPU寄存器的 ...

  6. java 如何只暴露接口_Java并发异步编程,原来十个接口的活现在只需要一个接口就搞定...

    什么?对你没有听错,也没有看错 ..多线程并发执行任务,取结果归集~~ 不再忧愁-. 引言 先来看一些APP的获取数据,诸如此类,一个页面获取N多个,多达10个左右的一个用户行为数据,比如:点赞数,发 ...

  7. java读写锁死锁例子_Java并发关于重入锁与读写锁的详解

    这篇文章主要介绍了Java并发编程之重入锁与读写锁,文中相关实例代码详细,测试可用,具有一定参考价值,需要的朋友可以了解下. 重入锁 重入锁,顾名思义,就是支持重进入的锁,它表示该锁能够支持一个线程对 ...

  8. java的尝试性问题_Java并发编程实战 03互斥锁 解决原子性问题

    文章系列 摘要 在上一篇文章02Java如何解决可见性和有序性问题当中,我们解决了可见性和有序性的问题,那么还有一个原子性问题咱们还没解决.在第一篇文章01并发编程的Bug源头当中,讲到了把一个或者多 ...

  9. java线程同步的实现_Java并发编程(三) - 实战:线程同步的实现

    synchronized关键字 首先,来看一个多线程竞争临界资源导致的同步不安全问题. package com.example.weishj.mytester.concurrency.sync; /* ...

  10. java统计系统线程数_Java并发(八)计算线程池最佳线程数

    目录 一.理论分析 二.实际应用 为了加快程序处理速度,我们会将问题分解成若干个并发执行的任务.并且创建线程池,将任务委派给线程池中的线程,以便使它们可以并发地执行.在高并发的情况下采用线程池,可以有 ...

最新文章

  1. 【面经】超硬核面经,已拿蚂蚁金服Offer!!
  2. python 编程该看那些书籍_初学者自学Python要看什么书?
  3. java源码编译为字节码的流程
  4. 文件系统:使用 yum 安装软件包
  5. VIP - virtual IP address
  6. MySQL线上备份与恢复方案
  7. 028-进阶(网络编程)
  8. webmin mysql_MySQL+Webmin轻松创建数据库
  9. python 下载bilibili视频
  10. 2017 ACM/ICPC(北京)总结
  11. 购物车=收藏夹?一文理解淘宝购物车背后的逻辑
  12. 苹果电脑上几款不错的图片编辑工具
  13. 电容屏物体识别_电容屏物体识别技术简介
  14. 共话新基建,墨天轮数据库大咖讲坛第一期圆满成功!(附第二批中奖名单)...
  15. pyhton BOF图像检索
  16. 获取Minecraft服务器信息API,Minecraft快速实现Yggdrasil API正版验证
  17. 递归查询数据库中树状数据
  18. Java实现斗地主的发牌以及展示
  19. 温度传感器Pt100 热电阻的原理
  20. 《阿里巴巴开发规范》读书笔记重点

热门文章

  1. 基于MATLAB绘制双纵坐标轴图
  2. 水经注CAD智能影像加载插件教程
  3. Python格式化输出总结
  4. 机电传动控制 第三周作业
  5. ai的预览模式切换_ai预览快捷键是什么,Adobe Illustrator预览快捷键是什么?
  6. logit方程怎么写_碳酸钠和氯化钙的化学方程式怎么写
  7. 数据库设计(一、二、三及BCNF范式)
  8. 大规模额外涨薪后,Intel又准备了24亿美元,明年再涨工资!
  9. linux debian安装字体,Debian安装/设置笔记(字体设置)
  10. B站有哪些程序员大牛up主?