public class Timer extends NotificationBroadcasterSupport implements TimerMBean, MBeanRegistration
此类管理一个过时的计时器通知列表。一种方法允许用户添加/删除所需的多个通知。当一个定时器通知由定时器发出并变得过时,它会自动从定时器通知列表中删除。
additional定时器通知可以被添加到规则重复的通知。
注:
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插入到一个给定的日期和一个空的时间和次数的通知列表。
|
Integer |
addNotification(String type, String message, Object userData, Date date, long period)
创建一个新的具有指定
type定时器通知,
message和
userData并把它插入到列表通知与一个给定的日期和时间和空的次数。
|
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服务器注册成功。价值错误意味着注册阶段已经失败。
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并把它插入到列表通知与一个给定的日期,时间和次数。
如果要插入的计时器通知有一个在当前日期之前的日期,该方法的行为就好像指定日期是当前日期。
一旦关闭通知,通知立即交付。定期通知
,第一通知立即交付和后续的参数指定的时间间隔。
请注意,一旦定时器通知已被添加到通知列表中,其关联的日期、期间和出现的次数不能被更新。
在一个周期的通知的情况下,参数固定收益值用于指定执行方案,指定Timer。
addNotification 接口
TimerMBean
type -定时器通知类型。
message -定时器通知的详细信息。
userData -定时器通知用户数据对象。
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并把它插入到列表通知与一个给定的日期,时间和次数。
如果要插入的计时器通知有一个在当前日期之前的日期,该方法的行为就好像指定日期是当前日期。
一旦关闭通知,通知立即交付。定期通知
,第一通知立即交付和后续的参数指定的时间间隔。
请注意,一旦定时器通知已被添加到通知列表中,其关联的日期、期间和出现的次数不能被更新。
在一个周期的通知的情况下,使用一个固定延迟执行方案,指定Timer。为了使用一个固定利率执行方案,而不是使用addNotification(String, String, Object, Date, long, long, boolean)。
addNotification 接口
TimerMBean
type -定时器通知类型。
message -定时器通知的详细信息。
userData -定时器通知用户数据对象。
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并把它插入到列表通知与一个给定的日期和时间和空的次数。
定时器的通知将会不断重复使用的定时器周期使用固定延迟执行方案,指定Timer。为了使用一个固定利率执行方案,而不是使用addNotification(String, String, Object, Date, long, long, boolean)。
如果要插入的计时器通知有一个在当前日期之前的日期,该方法的行为就好像指定日期是当前日期。第一通知立即发送,随后的通知按周期参数指定的间隔进行间隔开。
addNotification 接口
TimerMBean
type -定时器通知类型。
message -定时器通知的详细信息。
userData -定时器通知用户数据对象。
date时发生的日期通知。
period -定时器的通知时间(毫秒)。
IllegalArgumentException -日期
null或期负。
public Integer addNotification(String type, String message, Object userData, Date date) throws IllegalArgumentException
type定时器通知,
message和
userData插入到一个给定的日期和一个空的时间和次数的通知列表。
定时器通知将在指定的日期处理一次。
如果要插入的计时器通知有一个在当前日期之前的日期,该方法将表现为如果指定的日期是当前日期,并立即通知通知。
addNotification 接口
TimerMBean
type -定时器通知类型。
message -定时器通知的详细信息。
userData -定时器通知用户数据对象。
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对象包含所有定时器通知标识符向量。如果没有定时器通知注册这个定时器MBean
public Vector<Integer> getNotificationIDs(String type)
getNotificationIDs 接口
TimerMBean
type -定时器通知类型。
Integer对象包含定时器通知指定的
type所有标识符向量。如果没有定时通知注册这个定时器MBean指定的
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否则。
public boolean isEmpty()
isEmpty 接口
TimerMBean
true如果定时器通知列表是空的,
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.