VisualVM Java Profiler Causes Profiled JVM to Crash
VisualVM is a tool that integrates several management and monitoring tools for local and remote Java applications including a Java profiler. The VisualVM profiler enable you to analyze CPU and memory usage of local Java applications.
When attaching the VisualVM profiler to a Java application which is running on Java 6, the profiler may cause the Java application to crash. To prevent this from happening, you need to turn off class sharing for the Java application. Any Java application can be start with class sharing turned off by starting the application with the -Xshare:off argument.
Monday, June 02, 2008 | 2 Comments
Create log4j configuration file using wizardforge log4j wizard
Log4j is a widely used Java based logging framework. If you worked with Java open source projects you definitely used log4j in your applications. Controlling of the output of the logs is done using the log4j configuration. If you decided to use log4j in your Java application or you are using a 3rd party Java library which uses log4j for logging and requires log4j, you will need to write a log4j configuration file.
Using wizardforge log4j wizard we can create a log4j configuration file. This log4j wizard comes in handy when you do not know the log4j configuration file structure, syntax or if you forgot one of the appenders parameters.
Monday, April 14, 2008 | 0 Comments
JMX remote connection failure to Java application running on Ubuntu
I have been trying to remote monitoring my application which was running on Ubuntu server using Jconsole and I kept on getting connection failure.
When I run the same application on my Ubuntu desktop I did managed to connect to it using Jconsole.
I wrote a small program to help me investigate the problem:
public class JmxTest {
public static void main(String[] args) {
try {
Thread.sleep(Integer.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
and I ran it with the following properties on my Ubuntu desktop:
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=falseI have tried to connect to it using JConsole from a different machine on my network and I got the same error. I have tried to connect to the application using MX4J and I got the following exception:
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2239)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:271)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at org.mc4j.console.connection.JSR160ConnectionNode.connect(JSR160ConnectionNode.java:132)
at org.mc4j.console.connection.ReconnectAction.performAction(ReconnectAction.java:47)
at org.openide.util.actions.NodeAction$3.run(NodeAction.java:440)
at org.openide.util.actions.CallableSystemAction$ActionRunnable.actionPerformed(CallableSystemAction.java:247)
at org.netbeans.core.ModuleActions.invokeAction(ModuleActions.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.openide.util.actions.CallableSystemAction.invokeAction(CallableSystemAction.java:179)
at org.openide.util.actions.CallableSystemAction.access$000(CallableSystemAction.java:31)
at org.openide.util.actions.CallableSystemAction$ActionRunnable.doRun(CallableSystemAction.java:241)
at org.openide.util.actions.CallableSystemAction$2.run(CallableSystemAction.java:111)
at org.openide.util.Task.run(Task.java:136)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:330)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:686)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at java.net.Socket.<init>(Socket.java:367)
at java.net.Socket.<init>(Socket.java:180)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)
[catch] ... 23 more
I have noticed the
127.0.0.1 localhost
127.0.1.1 ubuntu-desktopI removed the 127.0.1.1 line and I moved the host name to the end of the first line:
127.0.0.1 localhost ubuntu-desktopAfter that I tried again to connect to my application using MX4J. This time I got the same exception but instead of 127.0.1.1 I got 127.0.0.1
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2239)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:271)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at org.mc4j.console.connection.JSR160ConnectionNode.connect(JSR160ConnectionNode.java:132)
at org.mc4j.console.connection.ReconnectAction.performAction(ReconnectAction.java:47)
at org.openide.util.actions.NodeAction$3.run(NodeAction.java:440)
at org.openide.util.actions.CallableSystemAction$ActionRunnable.actionPerformed(CallableSystemAction.java:247)
at org.netbeans.core.ModuleActions.invokeAction(ModuleActions.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.openide.util.actions.CallableSystemAction.invokeAction(CallableSystemAction.java:179)
at org.openide.util.actions.CallableSystemAction.access$000(CallableSystemAction.java:31)
at org.openide.util.actions.CallableSystemAction$ActionRunnable.doRun(CallableSystemAction.java:241)
at org.openide.util.actions.CallableSystemAction$2.run(CallableSystemAction.java:111)
at org.openide.util.Task.run(Task.java:136)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:330)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:686)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at java.net.Socket.<init>(Socket.java:367)
at java.net.Socket.<init>(Socket.java:180)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)
[catch] ... 23 moreAfter that I removed the host name from the file and I tried again, this time everything worked.
I have found this Blog entry about troubleshooting connection problems in jconsole. In my case the problem was different but it might be helpful to others .
Sunday, March 09, 2008 | 2 Comments
How to enable JMX on a Java Application
To enable Java with JMX Agent we need to add the following line to the application VM arguments:-Dcom.sun.management.jmxremote
This will enable only local monitoring. To enable remote JMX connection we need to specify the port which the JMX server will listen for remote connection.-Dcom.sun.management.jmxremote.port=9004 (or any other port number)
The JMX remote connection is secured by default. To disable the authentication or the SSL in the JMX remote connection:-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
much more information about monitoring and management using JMX can be found here
Tuesday, March 04, 2008 | 0 Comments