java lang

5217 ワード

いくつかのツール:jbe-0.1.1 jca 457.jar
キーワード
  • コンパイル
  •         -verbose
    javac -verbose ClassA.java
         ,      -classpath,(         )     import           
    ClassA.java(fisrtpackage) <=> ClassB.java(firstpackage.secondpackage)
    javac -verbose ClassA.java          ClassB.class ClassA.class
    
  • import
  • package
  •      ,   class     (           package  )。   java    ,java         (   , target.test11.Haha)      (     test11/Haha—— + )  ,         
     :javac             (-d target,           target/package    ),         .java         (      ),IDE   target   “  target  /package  ”
    
  • volatile
  •      JVM  
                  ,            ;                      (    )   volatile          ,    volatile              
    -
     volatile                          ,   IA-32           ,lock                    。
        •                     。
        •                CPU              。
               ,          ,                 (L1,L2   )      ,                ,      Volatile       ,JVM          Lock     ,                    。         ,               ,            ,        ,                ,           ,                                 ,                     ,                   ,                   ,                      。
          IA-32                      (   )      。
    java volatile      
       
    Java      :      Volatile   
    http://www.ibm.com/developerworks/cn/java/j-jtp06197.html
    >
        ++x         ( 、  、  )     
          volatile  (
                      。
                           。
        )
    

    Generics
    いくつかのテスト:
        /*List paramList = new ArrayList<>();
            paramList.add(11);
            paramList.add(12);
            testGenerics(paramList);*/
        //    ,   
        public static void testGenerics(List extends Number> paramList) {
            //   vs  
            // List super Number> srcList = new ArrayList();
            //       
            List srcList = new ArrayList();
            // next line can not add
            // extends   -        ,      (                    ,    )
            // List extends Number> srcList = new ArrayList();
            srcList.add(1);
            srcList.add(2);
            srcList.add(2.9);
            // super   -        ,      (        -        add,  no)
            // srcList.add(new Object());
            List destList = new ArrayList<>(); // or "? super Number"
            destList.add(3);
            destList.add(4);
            destList.add(5.1);
            Collections.copy(destList, srcList);
            System.out.println("success");
            //   
            Object value = paramList.get(0);
        }
    

    Javaにおけるインバータとコヒーレント
      、  、  
    PECS
    Collections.copy
        public static  void copy(List super T> dest, List extends T> src)
         (  、  )
    

    安全のために
    extends  
                  (List List)   ,    add,   (     )
    super  
        ? super X   ,   X   ( List),          (      ,     ;        get,            ),  add X        
    

    いくつかの約束
    1.  "?"
    https://stackoverflow.com/questions/678822/what-is-the-difference-between-and-object-in-java-generics
    HashMap hash1;
    is equivalent to
    HashMap hash1;
    Couple this knowledge with the "Get and Put Principle" in section (2.4) from Java Generics and Collections:
    
    The Get and Put Principle: use an extends wildcard when you only get values out of a structure, use super wildcard when you only put values into a structure, and don't use a wildcard when you both get and put.
    
    and the wild card may start making more sense
    
    2.
    

    reference
    WeakHashMap ThreadLocal dereference/purge CloseableThreadLocal
    マルチスレッド
    Dekkerアルゴリズムスレッドスケジューリング
                    
           
    cpu      
        cpu  ,     thread/process
         ,    cpu  
              ,    。        thread    
                 
             ,       ,     , blocking  ,        ,   notify()。notifyAll()    
      ,   ,             
               ,  cpu  ,          blocking  
        (        )   ,        ,    runnable  
      cpu  
           ,            ,       ,         ,     100000      blocking   ,             ,     100000       
             
                ,        ,    cpu, while  1000 ,  2     ,        2000     ,          
    #      ,         #
      ,        ,              ,            
    
            ,      
    
            ,"    ,          ,  while(true)             ,       ,          ,“           ,        false",                   ,        "       。
            ,"   Java  ,       tryLock              "       。
             ,          ,  
    while(true)
    {
    tryLock() == true?
    {
           do sth.
    }
    }
    

    Javaメモリモデル
    volatile(   synchronized?)      happen-before(       )
        (   )
         -   
    1.  、  、  
    2.     
    3.     i++  
       
    Atomic  compare and swap
        AtomicInteger.getAndDecrement
        (Unsafe.getAndAddInt(getIntVolatile/compareAndSwapInt))
    4.       
    5. (   /   )
    synchronized(  (  ?)/  )
    volatile    (no   )
        counter(volatile + synchronized)