如何从AS400中检索特定的JobList?

时间:2014-04-24 13:09:42

标签: java ibm-midrange jt400

我正在尝试检索符合我条件的活动进程列表。我已经有一个使用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,但如果有人有任何指导,我将不胜感激。

1 个答案:

答案 0 :(得分:3)

可以在系统上询问作业的子集;让IBM我做过滤工作而不是返回所有工作并让你的代码进行过滤。回答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();
    }

    }
}

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