Java

JAVA标准化的几个术语:JCP, JSR, RI, TCK

摘自wikipedia http://en.wikipedia.org/wiki/Java_Community_Process JCP — The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform. JSR — The JCP involves the use of Java Specification Requests (JSRs) – the formal documents that describe proposed …

JAVA标准化的几个术语:JCP, JSR, RI, TCK Read More »

Hotspot中的Permanent Generation

Permanent Generation跟Young Generation, Tenured Generation不是一个层次的概念,Young和Tenured是指Heap内部的划分,而Permanent Generation其实就是规范里的Method Area

学习JVM原理-1. Runtime Data Areas

摘自《深入理解Java虚拟机》周志明著 Runtime Data Areas分为五大部分:    1. Program Counter Register: 当前线程所执行的字节码的行号指示器,这里不会产生内存溢出问题    2. VM Stack: Java方法执行的内存模型。每个方法会占用一个栈帧,用于存储局部变量表,对象引用等。如果存储前申请不到足够的内存,会抛OutOfMemoryError;另外,如果栈深度大于JVM所容许的最大深度,则会抛StackOverflowError    3. Native Method Stacks: 与VM Stack作用相似,只不过它只针对虚拟机用到的Native方法。它也会抛OutOfMemoryError和StackOverflowError.    4. Heap: 用于存放对象实例,也称作GC堆。会抛OutOfMemoryError    5. Method Area: 存放类信息,常量,静态变量等。按规范在此可以选择不实现垃圾收集,但实践证明这里的GC是必要的。这里也会抛OutOfMemoryError 另外,JVM可以用"Direct Memory"的方式直接操纵本地内存(如NIO),如果这里申请的内存超过了本机总内存,则JVM也会抛OutOfMemoryError 举例说明:    Bean bean = new Bean();       1. "Bean bean"将会存入到VM Stack的局部变量表中    2. new Bean()这个对象实例将会存入到 Heap中    3. Bean这个类相关的数据将存入到Method Area …

学习JVM原理-1. Runtime Data Areas Read More »

关于System.gc()

javadoc说: Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.   注意,只是“建议”JVM干这样一种事,不是直接命令 …

关于System.gc() Read More »

Memory Leak & Memory Overflow

转自Wikipedia Memory Leak : it occurs when a computer program consumes memory but is unable to release it back to the operating system. In object-oriented programming, a memory leak happens when an object is stored in memory but cannot be accessed by the running code. Memory Overflow : it occurs where a program, while writing …

Memory Leak & Memory Overflow Read More »

认识一下 java.util.concurrent.locks

转自 http://download.oracle.com/javase/1.5.0/docs/guide/concurrency/overview.html The java.util.concurrent.locks package provides a high-performance lock implementation with the same memory semantics as synchronization, but which also supports specifying a timeout when attempting to acquire a lock, multiple condition variables per lock, non-lexically scoped locks, and support for interrupting threads which are waiting to acquire a lock.

动/静态类型和强/弱类型

摘自"Dive into Python" statically typed language     A language in which types are fixed at compile time. Most statically typed languages enforce this by requiring you to declare all variables with their datatypes before using them. Java and C are statically typed languages. dynamically typed language     A language in which types are discovered at …

动/静态类型和强/弱类型 Read More »

Tomcat/Jboss 中自定义 SESSION_COOKIE_NAME

即把session id的cookie名从默认的JSESSIONID改成其它的什么名字。解决办法是把这些名字以system property方式注入: Tomcat http://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html#Sessions org.apache.catalina.SESSION_COOKIE_NAME An alternative name for the session cookie. Defaults to JSESSIONID. Note that the Servlet specification requires this to be JSESSIONID. You should not rely on being able to change this. org.apache.catalina.SESSION_PARAMETER_NAME An alternative name for the session path parameter. Defaults to jsessionid. Note that the Servlet specification requires this …

Tomcat/Jboss 中自定义 SESSION_COOKIE_NAME Read More »

Tomat如何实现session

Servet Spec 规定了三种session tracking机制:   1.cookie (cookie name 必须是JSESSIONID)   2.url rewrite (即给URL加上,";jessionid=EDFGHGFRTYTYUI56789", e.g.)   3.如果当前处于SSL中,则servlet容器可以直接利用SSL中内置的会话跟踪机制实现自己的session 据不完全代码跟读,tomcat5.5并没有采用第3种方案(我也无法确证),所以这里只讨论前两种: 机制1: cookie a. 创建session时 => 服务端创建cookie,并通过http-response发到客户端 //org.apache.catalina.connector.Request. doGetSession() … //先创建session对象 // Creating a new session cookie based on that session if ((session != null) && (getContext() != null) && getContext().getCookies()) { Cookie cookie = new Cookie(Globals.SESSION_COOKIE_NAME, session.getIdInternal()); //注意:cookie的domain未设置 …

Tomat如何实现session Read More »