[英]Clear ehcache of remote server
我們如何清除遠程服務器上的ehcache
?
我的應用程序在登台環境(主機111.22.3.44
和端口17000
)中運行,我想編寫一個可以連接到給定host:port
的實用程序方法host:port
並清除我的應用程序的ehcache
。 該實用程序應該在Windows和Linux中都可以使用。
我使用JConsole.exe
實用程序來刷新在stage-server中創建的ehcache
的緩存,但是有一種情況我需要以編程方式執行它。
Hurrey ...... :)我得到了在遠程環境中清除ehcache
的解決方案。 在這里,我編寫了一個Java實用程序方法,它將清除由主機名和端口指定的給定遠程機器的ehcache
。
public void flushEhcache() throws IOException, NamingException, MalformedObjectNameException, NullPointerException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
String host = "111.22.3.44";
String port = "16000";
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"
+ host + ":" + port + "/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName beanName = new ObjectName("net.sf.ehcache:type=CacheManager,name=Your Application Name Here");
mbsc.invoke(beanName, "clearAll", new Object[0], new String[0]);
System.out.println("Flushed out ehcache succesfully");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.