ByteBuffer
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-heapperm | metaspace 3.off-heapjvm之外的內(nèi)容jvm調(diào)優(yōu)
-Xmx -Xms -Xmn //young -XX:NewSize= -XX:MaxNewSize=java -Xmx xx.x.xx.App
反射
動態(tài)訪問對象的屬性和方法。 Class //類 Method //方法,成員函數(shù) Field //字段,成員變量 Constructor //構(gòu)造函數(shù)privateField[] fs = getDeclaredFields() for(Field f : fs){ get + "" }
內(nèi)省
Introspector. 操作javabean。設(shè)計模式
單例(無狀態(tài)) 池化模式(無狀態(tài)) 裝飾 適配器 builder factory 代理模式.反射技術(shù).
Introspector: //JavaBean動態(tài)訪問對象屬性和方法。 Class // Method // Field // Constructor //IO
InputStream //read OuputStream //writeReader // Writer //字符流BufferedInpustStream // BufferedOutputStream //BufferedReader BufferedWriterInputStreamReader ObjectInputStream ObjectOutputStreamByteArrayInputStream ByteArrayOutputStreamNIO: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 //記號(標記)//分配字節(jié)緩沖區(qū) ByteBuffer buf = ByteBuffer.allocate(20); // ByteBuffer buf = ByteBuffer.allocateDirect(20); //直接內(nèi)存(離堆)java.nio.ByteBuffer/\|--------------java.nio.HeapByteBuffer //堆內(nèi)存區(qū)|--------------java.nio.DirectByteBuffer //離堆內(nèi)存區(qū).get() //讀put() //寫position() //取出指針位置position(int ) //設(shè)置指針新位置limit() //設(shè)置指針新位置limit(int l) //設(shè)置新limitflip() //0 <= mark <= position <= limit <= capacityGC
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方法的區(qū)別
對緩沖區(qū)的讀寫操作首先要知道緩沖區(qū)的下限、上限和當前位置。下面這些變量的值對Buffer類中的某些操作有著至關(guān)重要的作用:
1. limit:所有對Buffer讀寫操作都會以limit變量的值作為上限。
2. position:代表對緩沖區(qū)進行讀寫時,當前游標的位置。
3. capacity:代表緩沖區(qū)的最大容量(一般新建一個緩沖區(qū)的時候,limit的值和capacity的值默認是相等的)。
flip、rewind、clear這三個方法便是用來設(shè)置這些值的。
clear方法 public final Buffer clear() {position = 0; //重置當前讀寫位置limit = capacity; mark = -1; //取消標記return this; }clear方法將緩沖區(qū)清空,一般是在重新寫緩沖區(qū)時調(diào)用。
flip方法
public final Buffer flip() {limit = position;position = 0;mark = -1;return this; }反轉(zhuǎn)緩沖區(qū)。首先將限制設(shè)置為當前位置,然后將位置設(shè)置為 0。如果已定義了標記,則丟棄該標記。 常與compact方法一起使用。通常情況下,在準備從緩沖區(qū)中讀取數(shù)據(jù)時調(diào)用flip方法。
rewind方法
1public final Buffer rewind() { 2 position = 0; 3 mark = -1; 4 return this; 5}轉(zhuǎn)載于:https://www.cnblogs.com/yihaifutai/p/6787468.html
總結(jié)
以上是生活随笔為你收集整理的ByteBuffer的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大数据量高并发的数据库优化(转)
- 下一篇: [POJ2155] Matrix(二维线