Last active
February 10, 2017 13:41
-
-
Save rtio/195740296a159c7050630d6a8cfdae9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void clear(Scheduler scheduler) { | |
| Object quartzScheduler = getFieldValue(scheduler, "sched"); | |
| Object jobMgr = getFieldValue(quartzScheduler, "jobMgr"); | |
| @SuppressWarnings("unchecked") | |
| Map<String, JobExecutionContext> executingJobs = (Map<String, JobExecutionContext>)getFieldValue(jobMgr, "executingJobs"); | |
| List<String> removalList = new ArrayList<String>(); | |
| for(Map.Entry<String, JobExecutionContext> entry : executingJobs.entrySet()) { | |
| if(entry.getValue().getNextFireTime().before(new Date())) { | |
| removalList.add(entry.getKey()); | |
| } | |
| } | |
| for(String key : removalList) { | |
| executingJobs.remove(key); | |
| } | |
| } | |
| private Object getFieldValue(Object parent, String fieldName) { | |
| Object value = null; | |
| Class clazz = parent.getClass(); | |
| Field[] fields = clazz.getFields(); | |
| fields = clazz.getDeclaredFields(); | |
| for(Field field : fields) { | |
| if(field.getName().equalsIgnoreCase(fieldName)) { | |
| field.setAccessible(true); | |
| try { | |
| value = field.get(parent); | |
| } catch (IllegalArgumentException e) { | |
| value = null; | |
| } catch (IllegalAccessException e) { | |
| value = null; | |
| } | |
| } | |
| } | |
| return value; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment