3

我正在尝试检索符合我的条件的活动进程列表。我已经有了一个使用 JobList 的工作实现,它使用 as400 对象:

// New as400 object

as400Environment = new AS400();
as400Environment.setSystemName(systemName);
as400Environment.setUserId(userID);
as400Environment.setPassword(password);

// New Job list
JobList jobList = new JobList(as400Environment);
Enumeration e = jobList.getJobs();

while(e.hasMoreElements()) {

    // Store current job
    Job j = (Job) e.nextElement();

    // Do things with the job ........
}

但这需要很长时间才能找到我需要的根源,在某些计算机上长达 10 分钟。

我已经开始考虑使用子系统:

 Subsystem sbs = new Subsystem(as400Environment, subsystRequired, subsystRequired);

但我似乎无法将工作列表作为字符串,只能作为整数告诉我有多少工作。

无论如何,是否可以立即返回开销有限的工作清单?我现在仍在浏览 API,但如果有人有任何指导,将不胜感激。

4

1 回答 1

3

可以要求系统上的工作子集;让 IBM i 进行过滤工作,而不是返回所有作业并让您的代码进行过滤。回答16359926 有帮助吗?

编辑:粗过滤器代码

我想我理解这个问题。您想选择在特定子系统中运行的作业,但 addJobSelectionCriteria 不包括 SUBSYSTEM 作为筛选的可能选项之一。减少返回给您的工作数量的一种方法是仅过滤活动工作:

JobList jobList = new JobList(system);
jobList.clearJobSelectionCriteria();
jobList.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_ACTIVE, Boolean.TRUE);
jobList.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_JOBQ, Boolean.FALSE);
jobList.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_OUTQ, Boolean.FALSE);

获得活动作业列表后,您需要通过遍历枚举来测试代码中的子系统。提高效率的一种方法是调用 getJobs() 在它返回的属性列表中包含子系统名称。这将允许使用 getValue() 而不是 getSubsystem()。getSubsystem() 导致再次调用系统 API 来获取该信息,因此它的效率有些低。

jobList.clearJobAttributesToRetrieve();
jobList.addJobAttributeToRetrieve(Job.SUBSYSTEM);

那么,这里有一个简单的例子:

import java.util.*;
import com.ibm.as400.access.*;

public class TestGetJobList {
    public static void main(String[] args) {
       int raw=0;
       int selected=0;

try {
    AS400 system = new AS400();

    // Create a list and subset it
       // looking for all jobs in QINTER, but subsystem is not in the list of things we can filter on
       // so filter the list as small as possible and then this code will pick through that list
    JobList jobList = new JobList(system);
    jobList.clearJobSelectionCriteria();
    jobList.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_ACTIVE, Boolean.TRUE);
    jobList.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_JOBQ, Boolean.FALSE);
    jobList.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_OUTQ, Boolean.FALSE);

       // we can eliminate another call to the system API by adding subsystem to the attributes retrieved in the getJobList()
    jobList.clearJobAttributesToRetrieve();
    jobList.addJobAttributeToRetrieve(Job.SUBSYSTEM);
    jobList.addJobAttributeToRetrieve(Job.JOB_NAME);
    jobList.addJobAttributeToRetrieve(Job.JOB_NUMBER);
    jobList.addJobAttributeToRetrieve(Job.USER_NAME);

       // get the list of jobs
    Enumeration list = jobList.getJobs();

    while (list.hasMoreElements())  {
        Job  j= (Job) list.nextElement();
               raw++;    // count them

               // choose jobs in one subsystem
               // this is pretty efficient because we told getJobs() to include the subsystem in the first retrieval
               if (j.getValue(Job.SUBSYSTEM).toString().substring(0, 6).equals("QINTER")) {
                 selected++;
                 System.out.println(j.getValue(Job.JOB_NUMBER) + "/" +
                   j.getValue(Job.USER_NAME) + "/" +
                   j.getValue(Job.JOB_NAME) );
                 }
        }

    System.out.println(raw + " raw jobs found");
    System.out.println(selected + " QINTER jobs found");
    System.exit(0);

    } catch (Exception e) {
        e.printStackTrace();
    }

    }
}

这会在 1 秒内处理 500 个活动作业,在 QINTER 中选择大约 75 个。

于 2014-04-24T16:09:27.717 回答