Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to jmx with groovy faster

Tags:

groovy

jmx

I use weblogic example: http://groovy.codehaus.org/Groovy+and+JMX to connect jmx with groovy

Problem is that connection takes too long:

    long time = System.currentTimeMillis();

    println System.currentTimeMillis() - time;
    def server = JMXConnectorFactory.connect(serviceURL, h).MBeanServerConnection
    println System.currentTimeMillis() - time;

I have about 200 groovy script. Every script is doing something else but all need to connect to jmx. When I want to execute all it take about hour and more. Is there some options how to do it faster ?

like image 775
hudi Avatar asked Oct 22 '22 12:10

hudi


2 Answers

so the answer is very simpler. I need to use this project: http://kobo.github.io/groovyserv/

then I just created class JmxSharedConection with static method where I add connection and now it works much faster

like image 66
hudi Avatar answered Oct 29 '22 02:10

hudi


I would take tim's suggestion and implement a shared connection as a [synchronized] singleton. So in effect, you establish the connection once and then each script uses it as needed. For some extra pizass, register a connection listener to your JMXConnection, and when connectivity is lost, start a reconnect loop, throwing exceptions to the calling scripts until you reconnect.

like image 20
Nicholas Avatar answered Oct 29 '22 02:10

Nicholas