Developing Java Applications will mean at some point doing some memory management and memory leak troubleshooting. This does not imply that Java is bad or worst than any other programming language, but we need to be prepared to do this type of testing if the need arise. The cloud has been in many ways a benefit for all start ups and Proof of Concepts developers, at the same time is a benefit it introduce some difficulties if you compare the same practices that were developing in your own home computer. In this writers area, you will find some notes on how to enable java console within a Cloud instance in Amazon EC2.
Knowledge in Amazon EC2
How to start/stop Instance.
How to Modify security Groups.
How to install VNC Server in Red Hat or your favorite flavor of Linux.
Steps to Setup JConsole to troubleshoot in a cloud Server
Since we are using a local jconsole session JAVA_HOME/bin/jconsole then start your java application with the following options:
export JAVA_OPTS=”-Djava.awt.headless=true -server -Xms###m -Xmx###m -Dbuild.compiler.emacs=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=4999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false”
Please substitute the ### in Xms and Xmx with in the Initial heap size and maximum heap size in megabytes, respectively. The port that you will use to connect to jconsole is port 4999, and both authentication and ssl are set to false since you are using local jconsole.
This is taken directly from the Java Sun web site.
Local monitoring with jconsole is useful for development and prototyping. Using jconsole locally is not recommended for production environments, because jconsole itself consumes significant system resources. Rather, use jconsole on a remote system to isolate it from the platform being monitored.
For now we are going to do local monitoring, not because is easier, since in reality it is harder in the cloud to do local monitoring, just because you have to install software on your instance that are not installed by default and is not local for you eitherway.
- Install VNC server on your Linux machin, if you have are using redhat a simple “up2date install vnc-server” command.
- Make sure to open the Security Group in your cloud instance to port 5901, this is the default port for VNC Server.
- Now make sure you start the vnc service by typing in your console, “vncserver :1“
- Your java application is started with the options listed above, remember your jconsole port is 4999 or whatever number you entered there.
- Since the authentication option is set to false then you are going to be required to login locally and that is why we are installing vncserver.
- Now from any computer, using vnc-viewer type the ip address of your server followed with the colon “:” and the number entered in step 3.
- After you are login you will receive a super simple XTerminal.
- Left click and choose terminal window. From there go to the bin directory inside your java directory usually JAVA_HOME/bin/ and type “./jconsole &“.
Please watch the video below. It is a step by step copy of the steps 6-8. That way you will know if you are doing something wrong in any of those steps.