JobDetail job = newJob(HelloJob.class).withIdentity("job1", "group1").build();
Trigger trigger = newTrigger().withIdentity("trigger1", "group1").startAt(runTime).build();
The above code
-
What is the use of “group1” for JobDetail? Under what circumstances does it need to be used?
-
What’s the use of “group1” for Trigger? Under what circumstances does it need to be used?
The comment for the Schedule interface in the org.quartz package states:
* <p> * <code>Job</code> s and <code>Trigger</code> s have a name and group * associated with them, which should uniquely identify them within a single * <code>{@link Scheduler}</code>. The 'group' feature may be useful for * creating logical groupings or categorizations of <code>Jobs</code> s and * <code>Triggers</code>s. If you don't have need for assigning a group to a * given <code>Jobs</code> of <code>Triggers</code>, then you can use the * <code>DEFAULT_GROUP</code> constant defined on this interface. * </p>
It can be seen that group is used for classification, which is equivalent to a namespace.
In addition, what’s the use of analyzing group from equals? For example, do you judge whether two trigger or jobs are the same? For example, trigger, in the SimpleTriggerImpl class
@Override public boolean equals(Object o) { if(!(o instanceof Trigger)) return false; Trigger other = (Trigger)o; return !(other.getKey() == null || getKey() == null) && getKey().equals(other.getKey()); }
So, this equals method is the equals method in the superclass Key, and here we use group:
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() ! = obj.getClass()) return false; @SuppressWarnings("unchecked") Key<T> other = (Key<T>) obj; if (group == null) { if (other.group ! = null) return false; } else if (! group.equals(other.group)) return false; if (name == null) { if (other.name ! = null) return false; } else if (! name.equals(other.name)) return false; return true; bracket
Therefore, group is actually a classification, meaning command space.