版權全部。如需轉載,請保留做者及出處信息:http://blog.csdn.net/jmppok/article/details/41542963java
在使用vmware虛擬化平臺時,經過VIJAVA獲取VCenter中的Task信息, 若是調用超過30次,會拋出「java.rmi.RemoteException: VI SDK invoke exception:com.vmware.vim25.InvalidState「異常。vim
調用代碼:oop
ServiceInstance si = new ServiceInstance(new URL("https://192.168.0.100/sdk"), "administrator", "123456", true); int i=1; while(true) { TaskManager taskMgr = si.getTaskManager(); TaskFilterSpec tfs = new TaskFilterSpec(); tfs.setEventChainId(new int[]{2951}); try{ TaskHistoryCollector thc = taskMgr.createCollectorForTasks(tfs); TaskInfo[] tasks = null; while(true) { tasks = thc.readNextTasks(50); if(tasks==null) { break; } for(TaskInfo t : tasks) { System.out.println(t.key + " " + t.changeTag + " " + t.eventChainId + " " + t.getProgress() ); } } }catch(Exception e) { e.printStackTrace(); } System.out.println("--------------------------------------------------"+i); Thread.sleep(100); i++; }
運行30次之後拋出異常:.net
WARN : java.rmi.RemoteException: VI SDK invoke exception:com.vmware.vim25.InvalidState at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:122) at com.vmware.vim25.ws.VimStub.createCollectorForTasks(VimStub.java:1666) at com.vmware.vim25.mo.TaskManager.createCollectorForTasks(TaskManager.java:75) at com.lenovo.itcloud.vm.vmware.VmTaskManager.getTaskInfo(VmTaskManager.java:155) at com.lenovo.itcloud.vm.vmware.VmTaskManager.run(VmTaskManager.java:100) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505)
解決辦法:code
每次使用完畢TaskHistoryCollector 後, 須要調用destoryCollector()方法將其銷燬:blog
thc.destroyCollector();