Runtime的addShutdownHook(Thread thread)我明白,
可是Method类里的
public native Object invoke(Object obj,Object args[])
我看帮助文档也不是很明白,就是下面try{}里的2行,哪位知道呢? static {
Runtime runtime = Runtime.getRuntime();
Class c = runtime.getClass();
try {
Method m = c.getMethod("addShutdownHook", new Class[] { Thread.class } );
m.invoke(runtime, new Object[] { new ShutdownThread() });
}
catch (NoSuchMethodException nsme) {
//
}
catch (Exception e) {
e.printStackTrace();
}
}
private static class ShutdownThread extends Thread {
public void run() {
ConnectionProvider provider = ConnectionManager.getConnectionProvider();
if (provider != null) {
provider.destroy();
}
}
}
可是Method类里的
public native Object invoke(Object obj,Object args[])
我看帮助文档也不是很明白,就是下面try{}里的2行,哪位知道呢? static {
Runtime runtime = Runtime.getRuntime();
Class c = runtime.getClass();
try {
Method m = c.getMethod("addShutdownHook", new Class[] { Thread.class } );
m.invoke(runtime, new Object[] { new ShutdownThread() });
}
catch (NoSuchMethodException nsme) {
//
}
catch (Exception e) {
e.printStackTrace();
}
}
private static class ShutdownThread extends Thread {
public void run() {
ConnectionProvider provider = ConnectionManager.getConnectionProvider();
if (provider != null) {
provider.destroy();
}
}
}
解决方案 »
- HttpClient多线程的问题
- Struts1怎样实现DispatchAction配置多个input属性
- hibernate查询数据库 问题
- 关于JDK版本的问题
- 各位高手,晚上好。问一个servlet里面,怎么样链接数据库!
- jsp 获取访问者的url 怎么实现,请高手帮忙!!!!!
- 求推荐一本书!
- 定价字段是real 类型,当rs.getFloat("dingjia")时报错:Value can not be converted to requested type.
- myeclipse在jsp使用el表达示报错
- 刚入门SpringMVC 有个地方不明白
- 请问:网易126邮箱中邮件的拖放功能是使用什么技术实现的?????????
- 求jfreechart 0.9.21 demo代码
得到runtime类的static方法addShutdownHook
m.invoke(runtime, new Object[] { new ShutdownThread() });
执行这个方法