Java必讀源碼__Java

來源:互聯網
上載者:User
有能力了,必讀,看懂注釋,眼見為實
import sun.misc.Unsafe;import java.io.FileInputStream;import java.lang.reflect.Field;import java.util.*;import java.util.concurrent.*;import java.util.concurrent.atomic.AtomicInteger;import java.util.concurrent.atomic.LongAdder;import java.util.concurrent.locks.ReentrantLock;import java.util.concurrent.locks.ReentrantReadWriteLock;/** * 這些類的源碼必須看一下 * Created by Cherish on 2017/3/10. */public class NeedToRead {    public static void main(String[] args)  {        String string = "原來整型字面量編譯後是這樣的," +                "調用了Integer.valueOf(i),可以取緩衝";        Boolean bool = true;        Byte b = 1;        Character character = 'c';        Short shortI = 64;        Integer integer = 127;        Long l = 127L;        Float f = 0.0F;        Double d = 0.0;        Class clazz = Class.class;        StringBuilder stringBuilder = new StringBuilder(16);        StringBuffer stringBuffer = new StringBuffer(16);// toStringCache 有一個toString的緩衝        Thread thread = new Thread();        ThreadLocal threadLocal = new ThreadLocal();        ThreadLocalRandom random = ThreadLocalRandom.current();        //TODO 每個 TreadLocal 都只是一個鍵,它對應著 .set(value);        //TODO 用它本身作為鍵去  ThreadLocalMap 中擷取 value        threadLocal.set(random);        Object o = threadLocal.get();        System.out.println("o = " + o.getClass());        ThreadLocal threadLocal2 = new ThreadLocal();        threadLocal2.set(threadLocal);        Object o1 = threadLocal2.get();        System.out.println("o1.getClass() = " + o1.getClass());        //TODO 資料來源        //TODO java.util 及 concurrent 包,認真閱讀源碼        TreeMap rbTree = new TreeMap();        HashMap hashMap = new HashMap(8);        Iterator iterator = hashMap.entrySet().iterator();        ArrayList arrayList = new ArrayList();        LinkedList linkedList = new LinkedList();        AbstractQueue priorityQueue = new PriorityQueue();        BlockingQueue lbQueue = new LinkedBlockingQueue();        ConcurrentMap concurrentMap = new ConcurrentHashMap();        CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList();        AtomicInteger atomicInteger = new AtomicInteger();        LongAdder longAdder = new LongAdder();        ReentrantLock lock = new ReentrantLock();        ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();        ExecutorService executorService = Executors.newFixedThreadPool(5);        ForkJoinPool forkJoin = new ForkJoinPool();        ExecutorService threadPoolExecutor =                new ThreadPoolExecutor(5, 10, 5,                        TimeUnit.SECONDS, new LinkedBlockingQueue<>());        FutureTask futureTask = new FutureTask<>(()-> new Random().nextInt(100));        final String returnObj = "";        futureTask = new FutureTask<>(() -> {        }, returnObj);        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {            return "Hello CompletableFuture!";        });        CompletableFuture future = completableFuture.thenAccept(o2 -> {            System.out.println("thenAccept: " + o2);        });        FileInputStream fileInputStream;// 策略模式,裝飾者模式        Field theUnsafe = null;        try {            theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");            theUnsafe.setAccessible(true);            final Unsafe UNSAFE = (Unsafe) theUnsafe.get(null);            System.out.println(UNSAFE);        } catch (NoSuchFieldException | IllegalAccessException e) {            e.printStackTrace();        }    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.