About the Memory debug and heap dump tips in Java

About the Memory debug and heap dump tips:
Feb 2016 By W.ZH

It is needed to debug the java memeory usage when you face some issues like the OutOfMemoryError in Java.

Here is summary some common usages I used in projects:

1. How to trigger a automatically memory dump for a JVM when it faces a OutOfMemoryError?

Just add these options to the Java

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=PathOfDumpFileFolder

It will create a java_pid.hprof file in the DumpPath.


2. If you want to make a dump anytime when your system is running, just run this command when your applications running:

jmap -dump:file=path_to_file 12341234 here is your java process id.


3. How to open the HPROF file ro read the content of the heap?

You can use the eclipse plugin to do this. Normally I use “Memory Analyzer”
http://www.eclipse.org/mat/

After install the Plugin open this perspective to use it.

Window –> open perspective –> other –> Memmory Analysis

then go to menu of :

File –> Open Heap Dump  to read in a dump file.


4. How to dump in the eclipse environment?

Same with 3, use the “Memory Analyzer” http://www.eclipse.org/mat/

Use it to create a new dump project and do the dump. refer the some tips and tutorial of “Memory Analyzer”, Not hard to use it.

 

Advertisements

Jenkins Setup in 20 minitues

Feb 2016, By WZh

This some Jenkins key points to note down:

1. Get the jenkin war file from https://jenkins-ci.org/2. Install the tomcat server, to run in linux.

3. Copy the jenkins.war file to the webapp folder of the tomcat, restart tomcat.

then you can access this URL to access jenkins:

http://192.168.***.***/jenkins/

4. At this step, you are still using anonymous user to access jenkins.

5. jenkin will using a default folder to save all jenkins related data files into it.

You can change to other folder as you want , eg. /opt/jenkins

6. Go to “Manage Jenkins”–>”Configure System” to do basic config for a jenkins, major points:

1. JDK Name and JAVA_HOME  , or you can let jenkins to install the JDK automatically

2. ANT  refer to your ANT or let jenkins to install one for you.

3. MAVEN refer to your ANT or let jenkins to install one for you.

4. jenkins URL:     http://192.168.160.48/jenkins/

5. CVS or Subversion; if you use Subversion, you just need to select one version here. later in each job, you input svn URL and user accounts

just save it.

7. Create job and run job according your schedule:

Note:

1. “default” when you first time using ANT/Maven will cause issue when they are auto installer. S better to refer to the specific version for them.

2. Build periodically will use cron format, do a bit study for it.

If you want every five minitues:      */5 * * * *

If you want every one hour:         H */1 * * *

8. Maven project in you eclipse will be easily run in jenkin.

9. ANT project sometimes need to test and make the build.xml working fine both at eclipse and also the jenkins environment, and you may need to add change abit your ant xml.

10. use “Manage Jenkins”–>”Configure Global Security” to enable the security , normally will use the :

1. “Jenkins’ own user database” unless you intergrate with enterprise AD/LDAP

2. “Matrix-based security” to let each user be controlled.