Some Notes 20150818

##
public final void setDaemon(boolean on)
Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads.
This method must be invoked before the thread is started.

## How to check the options supported by yor JVM
java -XX:+AggressiveOpts -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal -version


##-XX:+TraceClassLoading -XX:+TraceClassUnloading
If you turn the options, you should be able to see below output when runing the applicationsj:
[Opened C:\Program Files\Java\jdk1.7.0_71\jre\lib\rt.jar]
[Loaded java.lang.Object from C:\Program Files\Java\jdk1.7.0_71\jre\lib\rt.jar]

##singleton-static
http://www.dotnetperls.com/singleton-static

##Big file memory map
http://hhyyllgg.iteye.com/blog/1921386
http://www.blogjava.net/killme2008/archive/2008/02/22/181357.html


##Buffer.flip()
  以ByteBuffer为例,
1、访问,通过get(),get(index),其中get()从当前position位置读取,get(index)从index位置读取,不改变当前position,下面要说到的put也一样。
2、填充,通过put(byte),put(index,byte),按照绝对位置填充也是不改变当前position属性

3、flipping,试想,我们将填充完毕的buffer传递给socket输出,那么socket读取是依据position属性确定,就会从结尾后一位开始读,这样肯定是不正确的,如果要正确的读取我们先要:
  buffer.limit(buffer.position( )).position(0);
将limit设为position, 将position设为0,这个操作就叫flipping,API直接提供了这个操作:
  buffer.flip( );
特别注意,flip()方法会改变limit属性,将limit属性从capacity设置为当前position。rewind()方法与flip()类似,但是仅将position设为0,而不改变limit,通常用于重新读取已经被flip的buffer。flip()另一个注意点是,两次调用buffer的flip方法,将使得position和limit属性都为0。

posted @ 2015-08-18 20:42  glf2046  阅读(94)  评论(0编辑  收藏  举报