InterruptedException和类的java不可访问捕获块。newInstance()
在当前项目中,我试图加载一组插件;问题是插件可以做任何事情,包括抛出异常,或者永远挂起。我正在努力实现以下目标:
try {
// load class by package name
Class<?> pluginClass = Class.forName(plginClassName);
// create a new instance of the object
// this call could throw an exception or never return
GenericPlugin plugin = (GenericPlugin) pluginClass.newInstance();
state = PluginState.INITIALIZED;
...
} catch ( InterruptedException ie ) { // <-- Compile Error Here
// Unreachable catch block for InterruptedException. This exception is never thrown from the try statement body
state = PluginState.TIMEOUT;
} catch ( Exception ex ) {
state = PluginState.FAILED;
}
我希望在装入器线程的调用类中,我可以执行以下操作:
LoaderThread t = new LoaderThread( pluginClassName );
// start loading the plugin
t.start();
// wait 5 seconds for startup
t.join( 5000 );
// interrupt if not complete
t.interrupt();
// get my plugin state
pluginState = t.getPluginState();
如果我做错了,请告诉我,但是
How can I timeout a call to
class.newInstance()
?
共 (0) 个答案