小皮2017-04-17 16:05:031楼
在 org.quartz 包中的 Schedule 接口的注释说明了:
*
* Job
s and Trigger
s have a name and group
* associated with them, which should uniquely identify them within a single
* {@link Scheduler}
. The 'group' feature may be useful for
* creating logical groupings or categorizations of Jobs
s and
* Triggers
s. If you don't have need for assigning a group to a
* given Jobs
of Triggers
, then you can use the
* DEFAULT_GROUP
constant defined on this interface.
*
可见, group 是用于分类的,相当于一个命名空间。
另外,从 equals 分析 group 有什么用。比如说,你是判断两个 trigger 或者 job 是一样的呢?比如 trigger,在 SimpleTriggerImpl 类中
@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());
}
那么,这个 equals方法就是 在超类 Key 中的equals 方法,这里就用到了 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 other = (Key) 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;
}
所以说,group 其实就是一个分类,命令空间的意思。