It is possible to ask for a subset of the jobs on the system; to have IBM i do the work of filtering rather than returning all the jobs and having your code do that filtering. Does answer 16359926 help?
EDIT: Code for crude filter
I think I understand the issue. You want to choose jobs running in a specific subsystem, but addJobSelectionCriteria does not include SUBSYSTEM as one of the possible choices to filter on. One way to reduce the number of jobs being returned to you is to filter on active jobs only:
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);
Once you have a list of active jobs, you'll need to test for subsystem in your code by looping through the Enumeration. One way to make that more efficient is to have the call to getJobs() include the subsystem name in the list of attributes it returns. This will enable the use of getValue() instead of getSubsystem(). getSubsystem() results in another call to the system API to get that information, so it is somewhat inefficient.
jobList.clearJobAttributesToRetrieve();
jobList.addJobAttributeToRetrieve(Job.SUBSYSTEM);
All together then, here is a simple example:
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();
}
}
}
This processes 500 active jobs, selecting about 75 in QINTER in under 1 second.