code: private ArrayList<ProcessInstance> getProcessInstances(Long process_id) {
          String getProInstances = "select * from PROCESS_INSTANCE where process_id=? and END_DT is null and (status_cd=7 or status_cd=2)"; // Workstatus 2,7
  
          DatabaseAccess db = new DatabaseAccess(null);
          final ArrayList<ProcessInstance> processVoList = new ArrayList<ProcessInstance>();
          try {
              db.openConnection();
              Object[] args = new Object[1];
              args[0] = process_id;
  
              ResultSet rs = db.runSelect(getProInstances, args);
              while (rs.next()) {
                  ProcessInstance processInstVO = new ProcessInstance();
                  processInstVO.setId(rs.getLong(1));
                  processInstVO.setProcessId(rs.getLong(2));
                  processInstVO.setStartDate(StringHelper.dateToString(rs.getTimestamp(8)));
                  processInstVO.setOwnerId(rs.getLong(4));
                  processInstVO.setMasterRequestId(rs.getString(15));
                  processInstVO.setActivities(getProcessInstanceActivity(rs.getLong(1)));
                  processVoList.add(processInstVO);
              }
          }
          catch (SQLException ex) {
              logger.severeException(ex.getMessage(), ex);
          }
          finally {
              db.closeConnection();
          }
  
          return processVoList;
      }
docs: /*
  Read  all process instances with wait or in progress stage and expired process SLAs