public class Timer extends NotificationBroadcasterSupport implements TimerMBean, MBeanRegistration
该类管理日期计时器通知的列表。 一种方法允许用户根据需要添加/删除尽可能多的通知。 当定时器发出定时器通知并变得过时时,它将自动从定时器通知列表中移除。
额外的定时器通知可以添加到定期重复的通知中。
注意:
Timer类的主机的系统日期。 如果主机具有不同的系统日期,侦听器可能会收到不及时的通知。 为了避免这种问题,请同步需要时间的所有主机的系统日期。 Timer中所述 。 为了使用固定速率执行 ,请使用过载的addNotification(String, String, Object, Date, long, long, boolean)方法。 NotificationBroadcasterSupport 。 | Modifier and Type | Field and Description |
|---|---|
static long |
ONE_DAY
一天中的毫秒数。
|
static long |
ONE_HOUR
一小时内的毫秒数。
|
static long |
ONE_MINUTE
一分钟内的毫秒数。
|
static long |
ONE_SECOND
一秒钟的毫秒数。
|
static long |
ONE_WEEK
一周内的毫秒数。
|
| Constructor and Description |
|---|
Timer()
默认构造函数。
|
| Modifier and Type | Method and Description |
|---|---|
Integer |
addNotification(String type, String message, Object userData, Date date)
创建具有
type
message和
userData的新计时器通知,
message其插入具有给定日期的通知列表,并显示空值和出现次数。
|
Integer |
addNotification(String type, String message, Object userData, Date date, long period)
创建具有
type
message和
userData的新定时器通知,
message其插入具有给定日期和期间的通知列表以及零次出现次数。
|
Integer |
addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences)
创建具有指定的新计时器通知
type ,
message和
userData并将其插入到与事件的定日期,时段和数量的通知列表中。
|
Integer |
addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences, boolean fixedRate)
创建具有指定的新计时器通知
type ,
message和
userData并将其插入到与事件的定日期,时段和数量的通知列表中。
|
Vector<Integer> |
getAllNotificationIDs()
获取注册到通知列表中的所有定时器通知标识符。
|
Date |
getDate(Integer id)
获取与定时器通知相关联的日期的副本。
|
Boolean |
getFixedRate(Integer id)
获取标志的副本,指示是定期通知是以
固定延迟还是
固定速率执行 。
|
int |
getNbNotifications()
获取注册到通知列表中的定时器通知的数量。
|
Long |
getNbOccurences(Integer id)
获取与定时器通知相关联的剩余发生次数的副本。
|
Vector<Integer> |
getNotificationIDs(String type)
获取与指定类型相对应的定时器通知的所有标识符。
|
MBeanNotificationInfo[] |
getNotificationInfo()
返回一个数组,指示MBean可能发送的每个通知,通知的Java类的名称和通知类型。
|
String |
getNotificationMessage(Integer id)
获取与指定标识符相对应的定时器通知详细消息。
|
String |
getNotificationType(Integer id)
获取与指定标识符对应的定时器通知类型。
|
Object |
getNotificationUserData(Integer id)
获取与指定标识符相对应的定时器通知用户数据对象。
|
Long |
getPeriod(Integer id)
获取与定时器通知相关联的周期(以毫秒为单位)的副本。
|
boolean |
getSendPastNotifications()
获取指示定时器是否发送过去通知的标志。
|
boolean |
isActive()
测试定时器MBean是否处于活动状态。
|
boolean |
isEmpty()
测试定时器通知的列表是否为空。
|
void |
postDeregister()
允许计时器MBean在MBean服务器取消注册后执行所需的操作。
|
void |
postRegister(Boolean registrationDone)
允许定时器MBean在MBean服务器中注册或注册失败后执行所需的操作。
|
void |
preDeregister()
允许计时器MBean在MBean服务器取消注册之前执行所需的任何操作。
|
ObjectName |
preRegister(MBeanServer server, ObjectName name)
允许计时器MBean在MBean服务器中注册之前执行所需的任何操作。
|
void |
removeAllNotifications()
从通知列表中删除所有定时器通知,并重置用于更新计时器通知标识符的计数器。
|
void |
removeNotification(Integer id)
从通知列表中删除与指定标识符相对应的定时器通知。
|
void |
removeNotifications(String type)
从通知列表中删除与指定类型对应的所有定时器通知。
|
void |
setSendPastNotifications(boolean value)
设置指示定时器是否发送过去通知的标志。
|
void |
start()
启动计时器。
|
void |
stop()
停止定时器
|
addNotificationListener, handleNotification, removeNotificationListener, removeNotificationListener, sendNotificationpublic static final long ONE_SECOND
addNotification方法有用常数。
public static final long ONE_MINUTE
addNotification方法有用常数。
public static final long ONE_HOUR
addNotification方法有用常数。
public static final long ONE_DAY
addNotification方法有用的常数。
public static final long ONE_WEEK
addNotification方法。
public ObjectName preRegister(MBeanServer server, ObjectName name) throws 异常
在此上下文中未使用。
preRegister在界面
MBeanRegistration
server - 定时器MBean将被注册的MBean服务器。
name - 定时器MBean的对象名称。
异常
public void postRegister(Boolean registrationDone)
在此上下文中未使用。
postRegister在界面
MBeanRegistration
registrationDone - 指示MBean是否已在MBean服务器中成功注册。
值false表示注册阶段失败。
public void preDeregister()
throws 异常
停止定时器
preDeregister在接口
MBeanRegistration
异常
public void postDeregister()
在此上下文中未使用。
postDeregister在界面
MBeanRegistration
public MBeanNotificationInfo[] getNotificationInfo()
NotificationBroadcaster复制
返回一个数组,指示MBean可能发送的每个通知,通知的Java类的名称和通知类型。
MBean发送不在此阵列中描述的通知并不是非法的。 但是,MBean服务器的某些客户端可能依赖于正确运行的阵列。
getNotificationInfo在界面
NotificationBroadcaster
getNotificationInfo在类别
NotificationBroadcasterSupport
public void start()
如果在通知列表中的时间之前有一个或多个定时器通知,则通知根据sendPastNotifications标志发送,然后根据其周期和剩余的发生次数进行更新。 如果计时器通知日期早于当前日期,则此通知将从通知列表中移除。
start在接口
TimerMBean
public void stop()
stop在界面
TimerMBean
public Integer addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences, boolean fixedRate) throws IllegalArgumentException
type , message和userData并将其插入到与事件的定日期,时段和数量的通知列表中。
如果要插入的计时器通知的日期在当前日期之前,该方法的行为就像指定的日期是当前日期一样。
对于一次性通知,通知将立即发送。
对于定期通知,第一个通知立即发送,后续的通知按照period参数指定。
请注意,一旦定时器通知已添加到通知列表中,则无法更新其关联的日期,周期和出现次数。
在周期性通知的情况下,参数固定利率的值用于指定执行方案,如在指定的Timer 。
addNotification在接口
TimerMBean
type - 定时器通知类型。
message - 定时器通知详细信息。
userData - 定时器通知用户数据对象。
date - 发生
date的日期。
period - 定时器通知的周期(以毫秒为单位)。
nbOccurences - 将发出定时器通知的总数。
fixedRate - 如果true并且如果通知是周期性的,则通知以固定速率执行方案进行调度。
如果false并且如果通知是周期性的,则通知使用固定延迟执行方案进行调度。
如果通知不是周期性的,则忽略。
IllegalArgumentException - 日期为
null或期间或出现次数为负。
addNotification(String, String, Object, Date, long, long)
public Integer addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences) throws IllegalArgumentException
type , message和userData并将其插入到与事件的定日期,时段和数量的通知列表中。
如果要插入的计时器通知的日期在当前日期之前,该方法的行为就像指定的日期是当前日期一样。
对于一次性通知,通知将立即发送。
对于定期通知,第一个通知立即发送,后续的通知按照period参数指定。
请注意,一旦定时器通知已添加到通知列表中,则无法更新其关联的日期,周期和出现次数。
在周期性通知的情况下,使用固定的延迟执行方案,如在指定的Timer 。 为了使用固定速率执行方案,请改用addNotification(String, String, Object, Date, long, long, boolean) 。
addNotification在界面
TimerMBean
type - 定时器通知类型。
message - 定时器通知详细信息。
userData - 定时器通知用户数据对象。
date - 发生
date的日期。
period - 定时器通知的周期(以毫秒为单位)。
nbOccurences - 将发出定时器通知的总数。
IllegalArgumentException - 日期为
null或出现的期间或次数为负。
addNotification(String, String, Object, Date, long, long, boolean)
public Integer addNotification(String type, String message, Object userData, Date date, long period) throws IllegalArgumentException
type message和userData的新定时器通知, message其插入具有给定日期和期间的通知列表以及零次出现次数。
定时器通知将使用固定延迟执行方案使用定时器周期连续重复,如Timer中所述 。 为了使用固定速率执行方案,请改用addNotification(String, String, Object, Date, long, long, boolean) 。
如果要插入的计时器通知的日期在当前日期之前,该方法的行为就像指定的日期是当前日期一样。 第一个通知立即发送,随后的通知按照period参数指定。
addNotification在界面
TimerMBean
type - 定时器通知类型。
message - 定时器通知详细信息。
userData - 定时器通知用户数据对象。
date - 发生
date的日期。
period - 定时器通知的周期(以毫秒为单位)。
IllegalArgumentException - 日期为
null或期间为负。
public Integer addNotification(String type, String message, Object userData, Date date) throws IllegalArgumentException
type , message和userData并将其插入到与事件给定日期以及null时段和数量的通知列表中。
计时器通知将在指定的日期处理一次。
如果要插入的计时器通知的日期在当前日期之前,该方法的行为就像指定的日期是当前日期一样,并且立即发送通知。
addNotification在界面
TimerMBean
type - 定时器通知类型。
message - 定时器通知详细消息。
userData - 定时器通知用户数据对象。
date - 发生
date的日期。
IllegalArgumentException - 日期是
null 。
public void removeNotification(Integer id) throws InstanceNotFoundException
removeNotification在界面
TimerMBean
id - 定时器通知标识符。
InstanceNotFoundException - 指定的标识符与此定时器MBean的通知列表中的任何定时器通知不对应。
public void removeNotifications(String type) throws InstanceNotFoundException
removeNotifications在界面
TimerMBean
type - 定时器通知类型。
InstanceNotFoundException - 指定类型与此定时器MBean的通知列表中的任何定时器通知不对应。
public void removeAllNotifications()
removeAllNotifications在界面
TimerMBean
public int getNbNotifications()
getNbNotifications在界面
TimerMBean
public Vector<Integer> getAllNotificationIDs()
getAllNotificationIDs在界面
TimerMBean
Integer对象的向量。
public Vector<Integer> getNotificationIDs(String type)
getNotificationIDs在界面
TimerMBean
type - 定时器通知类型。
Integer对象的矢量, Integer指定的type的定时器通知的所有type 。
type 。
public String getNotificationType(Integer id)
getNotificationType在界面
TimerMBean
id - 定时器通知标识符。
public String getNotificationMessage(Integer id)
getNotificationMessage在接口
TimerMBean
id - 定时器通知标识符。
public Object getNotificationUserData(Integer id)
getNotificationUserData在接口
TimerMBean
id - 定时器通知标识符。
public Date getDate(Integer id)
getDate在界面
TimerMBean
id - 定时器通知标识符。
public Long getPeriod(Integer id)
getPeriod在界面
TimerMBean
id - 定时器通知标识符。
public Long getNbOccurences(Integer id)
getNbOccurences在界面
TimerMBean
id - 定时器通知标识符。
public Boolean getFixedRate(Integer id)
getFixedRate在界面
TimerMBean
id - 定时器通知标识符。
public boolean getSendPastNotifications()
false 。
getSendPastNotifications在界面
TimerMBean
setSendPastNotifications(boolean)
public void setSendPastNotifications(boolean value)
false 。
setSendPastNotifications在接口
TimerMBean
value - 过去通知发送开/关标志值。
getSendPastNotifications()
public boolean isActive()
isActive在界面
TimerMBean
true如果定时器MBean处于活动状态,
false false。
public boolean isEmpty()
isEmpty在界面
TimerMBean
true如果定时器通知列表为空,
false false。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.