To obtain the list of recent tasks, use a PropertyCollector to obtain references to the TaskManager and to all Task objects from the recentTask property of the TaskManager.

The following example shows an excerpt from the TaskList.java sample that creates the ObjectSpec, PropertySpec, and a TraversalSpec to obtain references to all Task objects on the server from the TaskList. See also Property Collector.

PropertyFilterSpec Definition to Obtain recentTask Property Values

private PropertyFilterSpec[] createPFSForRecentTasks(ManagedObjectReference taskManagerRef) {
     PropertySpec pSpec = new PropertySpec();
          pSpec.setAll(Boolean.FALSE);
          pSpec.setType("Task");
          pSpec.setPathSet(new String[] {"info.entity", "info.entityName", "info.name",
              "info.state", "info.cancelled", "info.error"});
     ObjectSpec oSpec = new ObjectSpec();
          oSpec.setObj(taskManagerRef);
          oSpec.setSkip(Boolean.FALSE);
     TraversalSpec tSpec = new TraversalSpec();
          tSpec.setType("TaskManager");
          tSpec.setPath("recentTask");
          tSpec.setSkip(Boolean.FALSE);
     oSpec.setSelectSet(new SelectionSpec[]{tSpec});
     PropertyFilterSpec pfSpec = new PropertyFilterSpec();
          pfSpec.setPropSet(new PropertySpec[]{pSpec});
          pfSpec.setObjectSet(new ObjectSpec[]{oSpec});
     return new PropertyFilterSpec[]{pfSpec};
}

For ESXi hosts managed by vCenter Server, use a TaskHistoryCollector. See Using a TaskHistoryCollector.