runtime data area
1.method area(共享)
2.heap (共享)
3.java stack(非)
4.native method stack(非)
5.program couter register(非)
method frame(stack frame)
从heap角度
1.heap //
young gen(eden + survivor0 + survivor 2) + old gen.
2.non-heap
perm | metaspace
3.off-heap
jvm之外的内容
jvm调优
-Xmx
-Xms
-Xmn //young
-XX:NewSize=
-XX:MaxNewSize=
java -Xmx xx.x.xx.App
反射
动态访问对象的属性和方法。
Class //类
Method //方法,成员函数
Field //字段,成员变量
Constructor //构造函数
private
Field[] fs = getDeclaredFields() for(Field f : fs){ get + "" }
内省
Introspector.
操作javabean。
设计模式
单例(无状态)
池化模式(无状态)
装饰
适配器
builder
factory
代理模式.
反射技术.
Introspector: //JavaBean
动态访问对象属性和方法。
Class //
Method //
Field //
Constructor //
IO
InputStream //read
OuputStream //write
Reader //
Writer //字符流
BufferedInpustStream //
BufferedOutputStream //
BufferedReader
BufferedWriter
InputStreamReader
ObjectInputStream
ObjectOutputStream
ByteArrayInputStream
ByteArrayOutputStream
NIO:New IO
ServerSocket ss = new ServerSocket(8888);
//阻塞的
while(true){
Socket s = ss.accept();
InputStream is = s.getInputStream();
//阻塞的
while(true){
is.read(buf);
}
...
}
NIO : java.nio.Buffer
[java.nio.Buffer]
容器,线性的,有限的.
Capacity //容量
limit //限制
position //指针位置
mark //记号(标记)
//分配字节缓冲区
ByteBuffer buf = ByteBuffer.allocate(20); //
ByteBuffer buf = ByteBuffer.allocateDirect(20); //直接内存(离堆)
java.nio.ByteBuffer
/
|--------------java.nio.HeapByteBuffer //堆内存区
|--------------java.nio.DirectByteBuffer //离堆内存区.
get() //读
put() //写
position() //取出指针位置
position(int ) //设置指针新位置
limit() //设置指针新位置
limit(int l) //设置新limit
flip() //
0 <= mark <= position <= limit <= capacity
GC
garbage collection,垃圾回收。
对象回收的条件:没有任何一个指针能够直接或间接达到的话,就回收了。
Person p = new Person();
Person p2 = p ;
p = null ;
List<Person> list = new ArrayList<Person>();
list.add(p2);
p2 = null ;
list.clear();
ByteBuffer.flip()
java.nio.ByteBuffer中flip、rewind、clear方法的区别
对缓冲区的读写操作首先要知道缓冲区的下限、上限和当前位置。下面这些变量的值对Buffer类中的某些操作有着至关重要的作用:
1. limit:所有对Buffer读写操作都会以limit变量的值作为上限。
2. position:代表对缓冲区进行读写时,当前游标的位置。
3. capacity:代表缓冲区的最大容量(一般新建一个缓冲区的时候,limit的值和capacity的值默认是相等的)。
flip、rewind、clear这三个方法便是用来设置这些值的。
clear方法
public final Buffer clear()
{
position = 0; //重置当前读写位置
limit = capacity;
mark = -1; //取消标记
return this;
}
clear方法将缓冲区清空,一般是在重新写缓冲区时调用。
flip方法
public final Buffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
反转缓冲区。首先将限制设置为当前位置,然后将位置设置为 0。如果已定义了标记,则丢弃该标记。 常与compact方法一起使用。通常情况下,在准备从缓冲区中读取数据时调用flip方法。
rewind方法
1public final Buffer rewind() {
2 position = 0;
3 mark = -1;
4 return this;
5}