Java - illyfrancis/scribble GitHub Wiki
And the memory allocation in 32bit OS etc. Because JVM requires a contiguous memory, in 32bit OS the max VM heap allocation is usually 1.2G to 1.6G according to the blog. Although that's that the limitation of the VM. The alternative is to use 64bit OS.
-
-Xms: Sets the initial heap size for when the JVM starts. -
-Xmx: Sets the maximum heap size. -
-Xmn: Sets the size of the Young Generation. -
-XX:PermSize: Sets the starting size of the Permanent Generation. -
-XX:MaxPermSize: Sets the maximum size of the Permanent Generation
The Xmx and permgen space are separate. [http://rimuhosting.com/knowledgebase/linux/java/-Xmx-settings]
If you get java.lang.OutOfMemoryError: PermGen, increase pergen using XX:MaxPermSize like -XX:MaxPermSize=128m, the default is 64M.
http://www.kdgregory.com/index.php?page=java.outOfMemory
Caused by:
- Permgen (as above), which is separate from the 'main' heap
- Thread allocation
- Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
- and more refer to the blog
- Visual Tutorial from Oracle
- http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html#RequiredSoftware
- Presentation: Visualizing Java Garbage Collection
- according to presentation the 'mandatory' flags are:
-verbose:gc-
-Xloggc:<pathtofile>path to the log output, make sure you've got disk space -
-XX:+PrintGCDetailsminimum information for tools to help, place-verbose:gcwith this -
-XX:+PrintTenuringDistributionpremature promotion information
- it's no longer need to set
-Xmsand-Xmxto the same value, it was a workaround 3 - 4 years ago but no longer need to. (around 0:42)
- according to presentation the 'mandatory' flags are:
Worth checking out
public class ThreadLocalExample {
// SimpleDateFormat is not thread-safe, so give one to each thread
private static final ThreadLocal<SimpleDateFormat> formatter = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue()
{
return new SimpleDateFormat("yyyyMMdd HHmm");
}
};
public String formatIt(Date date)
{
return formatter.get().format(date);
}
}http://javapapers.com/core-java/threadlocal/
Since Java 7.
private static final ThreadLocal localRandom =
new ThreadLocal() {
protected ThreadLocalRandom initialValue() {
return new ThreadLocalRandom();
}
};http://www.c2.com/cgi/wiki?DoubleBraceInitialization
http://www.c2.com/cgi/wiki?JavaIdioms
Use java -classpath ./lib/* app.Main instead of
java -classpath ./lib/log4j.jar:./lib/another.jar... app.Main
http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
hidden features listed in so
http://stackoverflow.com/questions/15496/hidden-features-of-java?rq=1