java - Quartz中,对job和trigger都要定义一个组名字(group),这个组有什么用处?
PHPz
PHPz 2017-04-17 16:03:03
0
1
2367
JobDetail job = newJob(HelloJob.class).withIdentity("job1", "group1").build();

Trigger trigger = newTrigger().withIdentity("trigger1", "group1").startAt(runTime).build();

如上代码

  1. 对于JobDetail,"group1"有什么用处?在什么情况下需要用到它?

  2. 对于Trigger,"group1"有什么用处?在什么情况下需要用到它?

PHPz
PHPz

学习是最好的投资!

reply all(1)
洪涛

The comments of the Schedule interface in the org.quartz package state:

 * <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 and is equivalent to a namespace.

Also, what is the use of analyzing group from equals. For example, do you judge that two triggers 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());

    }

Then, this equals method is the equals method in the super class Key, and group is used here:

@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;
    }

So, group is actually a classification, which means command space.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template