Showing posts with label jvm. Show all posts
Showing posts with label jvm. Show all posts

Monday, March 30, 2015

Set Tomcat encoding to UTF-8

By default, Tomcat uses ISO-8859-1 encoding, but there is a way to completely set tomcat using UTF-8.

-Dfile.encoding=UTF-8
Set JVM default encoding to UTF-8. Charset.defaultCharset() will reflect changes to the file.encoding property.

set JAVA_OPTS=-Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8
or Use a character encoding filter with the default encoding set to UTF-8, for HTTP POST

Set URIEncoding="UTF-8" on your <Connector> in server.xml.
<Connector port="8080" URIEncoding="UTF-8"/> for HTTP GET

For returned response, set
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");


http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q8
http://stackoverflow.com/questions/138948/how-to-get-utf-8-working-in-java-webapps

Monday, April 9, 2012

JVM memory model 101

Heap
    Young Generation
        Eden space, two Survivor (From/To) spaces                   
    Old Generation
        Tenured space
Non-Heap (Perm + C-Heap)
    Permanent Space
    Class files and jar files
    Code Generation
    Socket Buffers
    Thread stacks
    Direct Memory Space
    JNI Code
    Garbage Collection
    JNI allocated memory

Space Allocation
-Xmx -Xms -Xmn -Xss
Young size(-XX:NewRatio)
Survivor Ratio(-XX:SurvivorRatio)
-XX:PermSize=<value> (initial)
-XX:MaxPermSize=<value> (max)
-XX:MaxDirectMemorySize=<value>


Concurrent/Parallel Garbage Collection Settings
-XX:+UseParNewGC
Parallel GC in the New(Young) Generation
-XX:+UseConcMarkSweepGC
Concurrent in the Old generation
Use these two combined
Multiple CPU box can take advantage of this

More GC Settings:
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:+CMSIncrementalDutyCycleMin=0
-XX:+CMSIncrementalDutyCycle=10
-XX:+CMSPermGenSweepingEnabled

Debug
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+TraceClassUnloading
-XX:+HeapDumpOnOutOfMemoryError

Update 4/25/2012
http://javaeesupportpatterns.blogspot.com/2011/02/java-hotspot-vm-permgen-space.html

https://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation
Java classes are stored in the permanent generation. What all does that entail? Besides the basic fields of a Java class there are
  • Methods of a class (including the bytecodes)
  • Names of the classes (in the form of an object that points to a string also in the permanent generation)
  • Constant pool information (data read from the class file, see chapter 4 of the JVM specification for all the details, including static fields)
  • Object arrays and type arrays associated with a class (e.g., an object array containing references to methods)
  • Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance)
  • Information used for optimization by the compilers (JITs)