• Post Reply Bookmark Topic Watch Topic
  • New Topic

GarbageCollectorMXBean getCollectionCount throws java.io.IOException: The client has been closed.  RSS feed

 
Raghavendra Neelekani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a Java application where I am using Java GarbageCollectorMXBean APIs to get the collection count at regular intervals (for every 5 seconds). Below is the program I have written to do the task.


he program runs fine but sometimes it starts giving following IOException repeatedly in every loop.

Exception in thread "main" java.io.IOException: The client has been closed.
at java.util.TimerThread.run(Timer.java:505)
at com.sun.jmx.remote.internal.ClientCommunicatorAdmin.restart(ClientCommunicatorAdmin.java:94)
at com.sun.jmx.remote.internal.ClientCommunicatorAdmin.gotIOException(ClientCommunicatorAdmin.java:54)
at javax.management.remote.rmi.RMIConnector$RMIClientCommunicatorAdmin.gotIOException(RMIConnector.java:1470)
at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.getAttribute(RMIConnector.java:906)
at com.ibm.lang.management.OpenTypeMappingIHandler$6.run(OpenTypeMappingIHandler.java:506)
at java.security.AccessController.doPrivileged(AccessController.java:330)
at com.ibm.lang.management.OpenTypeMappingIHandler.invokeAttributeGetter(OpenTypeMappingIHandler.java:501)
at com.ibm.lang.management.OpenTypeMappingIHandler.invoke(OpenTypeMappingIHandler.java:121)
at com.sun.proxy.$Proxy112.getCollectionCount(Unknown Source)
at JMXTest.main(JMXTest.java:37)


But if we look at the code, for any exception it will get caught in catch block where all the fields will be initialized to null and in the next loop all the fields will be reinitialized. But looking at the logs, Once the exception starts coming, I get above exception only at getCollectionCount() call in every loop. I wonder even though the objects are re initialized, every time I get same exception.

I am looking at following things from the above information

In what all cases, we get this exception java.io.IOException: The client has been closed. in the above scenario. I know if we call jmxConnector.close() and then use the already created garbageCollectorMXBean object to get the collection count, we get this. But my code does not follow that path.
For the above issue, does jmxserver remote JMX server contributes ? I tried to reproduce by stopping/restarting the remote JMX server, but could not do it.
Any help in this regard ?


 
K. Tsang
Bartender
Posts: 3632
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I have added code tags making it easier to read.

As for your question, the stack trace indicated line 48 of the main method. Can you identify exactly what line that is? I doubt it's the line 48 posted.

Also if your main "throws Exception", you ought not to catch it. If you want to close those connections, do it in a finally block.

 
Raghavendra Neelekani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks for the reply. I have edited the exception stack trace to have proper line number. It might have changed while formatting with'code' tag.
The exception is happening at 37 line number where garbageCollectorMXBean is making getCollectionCount() call. I dont want to close the connections in the finally block because I want to close all connections and make everything null only when any exception happens. If everything goes smooth, then in the next loop, it should use already created objects to get the Collection Count..
 
K. Tsang
Bartender
Posts: 3632
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is indeed line 37 then the variable "garbageCollectorMXBean" is null. Meaning the null check/ initialization code didn't run properly.

Not sure if this going to solve your problem, but let put those instance variables (line 14,15,16) as local variables in main method (outside while loop).

This way the scope of these variables will be clearer.
 
Raghavendra Neelekani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The null check is all proper because the code works properly at positive scenarios. Some times while running, randomly it starts giving the exception and continues to give. The exception is happening at line 'garbageCollectorMXBean.getCollectionCount()' and it is not throwing NullPointerException but IOException. The scope of the variables are all proper because it works fine in most of the cases.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!