java lang
5217 ワード
いくつかのツール:jbe-0.1.1 jca 457.jar
キーワードコンパイル import package volatile
Generics
いくつかのテスト:
Javaにおけるインバータとコヒーレント
安全のために
いくつかの約束
reference
WeakHashMap ThreadLocal dereference/purge CloseableThreadLocal
マルチスレッド
Dekkerアルゴリズムスレッドスケジューリング
Javaメモリモデル
キーワード
-verbose
javac -verbose ClassA.java
, -classpath,( ) import
ClassA.java(fisrtpackage) <=> ClassB.java(firstpackage.secondpackage)
javac -verbose ClassA.java ClassB.class ClassA.class
, class ( package )。 java ,java ( , target.test11.Haha) ( test11/Haha—— + ) ,
:javac (-d target, target/package ), .java ( ),IDE target “ target /package ”
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
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
いくつかの約束
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)