编程语言
首页 > 编程语言> > java-如何从AS400检索特定的JobList?

java-如何从AS400检索特定的JobList?

作者:互联网

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

解决方法:

可以要求系统中的一部分作业.让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();
    }

    }
}

这将处理500个活动作业,并在一秒钟之内在QINTER中选择约75个作业.

标签:jt400,java,ibm-midrange
来源: https://codeday.me/bug/20191121/2054660.html