Closing a JMX Connection for Parallel Operations

I open a JMX connection using a method getMBeanServerConnection(), and then close it after use in the finally block. And for a given JMX connector, 2 successful calls getMBeanServerConnection()usually return the same MBeanServerConnection.

Some of the operations are called simultaneously, and each of them calls getMBeanServerConnection(). But they get such a connection. And therefore, when the first operation is completed, the remaining operation will complete with the error “Connection closed”.

How can i solve this? Do I have to create several connector objects and call getMBeanServerConnection()on them to get different connections? Or do I need to make this method synchronized (and reduce efficiency)?

+3
source share
1 answer

I think the short answer is that you need to use synchronization and take a performance hit.

Given that JMX calls are RMI / network based, a block synchronizedwould be very cheap in comparison. Any solution that you implement that has a usage counter will suffer from race conditions, especially considering that the JMXConnector most likely does not have protection against closing / joining conditions. For example, someone may close the connection at the same time that someone is connecting, and the new connection may be closed.

I think you should write a wrapper class (or method) for the connector. It would be:

  • , connect() ( 0), getMBeanServerConnection() .
  • close, , 0.
  • , .

.

+3

Source: https://habr.com/ru/post/1766837/


All Articles