Java7并发编程实战手册-读书笔记

2020-11-09  本文已影响0人  landon30

Java7并发编程实战手册

线程管理

线程同步基础

线程同步辅助类

线程执行器


Fork/Join框架


if(problem size > default size)
{
    tasks = divide(task)
    execute(tasks)
 }
 else {resolve problem using another algorithm}

并发集合


 public class Singleton {   
 
    private static final AtomicReference<Singleton> INSTANCE = new AtomicReference<Singleton>();  
      
    private Singleton (){}   
     
    public static  Singleton getInstance() {            
    for (;;) {            
        Singleton current = INSTANCE.get();                 
        if (current != null) {                
        return current;            
        }            
        current = new Singleton();            
        if (INSTANCE.compareAndSet(null, current)) {                
        return current;           
        }       
    }    
    }
  
}

定制并发类


   for(;;)
     {
      int value = get();
      if(value == 10) return false;
      else
      {
       int newValue = value + 1;
       boolean changed = compareAndSet(value,newValue);
       if(changed) return true;
      }
     }

测试并发应用程序

上一篇 下一篇

猜你喜欢

热点阅读