vmware vijava客户端调用异常

版权所有。如需转载,请保留作者及出处信息:http://blog.csdn.net/jmppok/article/details/41542963


在使用vmware虚拟化平台时,通过VIJAVA获取VCenter中的Task信息, 如果调用超过30次,会抛出“java.rmi.RemoteException: VI SDK invoke exception:com.vmware.vim25.InvalidState“异常。

调用代码:

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次以后抛出异常:

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)



解决办法:

每次使用完毕TaskHistoryCollector 后, 需要调用destoryCollector()方法将其销毁:

thc.destroyCollector();

你可能感兴趣的:(vmware,VCenter,虚拟化,vsphere,vijava)