所有类


javax.management.timer
类 Timer

java.lang.Object
  继承者 javax.management.NotificationBroadcasterSupport
      继承者 javax.management.timer.Timer
所有已实现的接口:
MBeanRegistration, NotificationBroadcaster, NotificationEmitter, TimerMBean

public class Timer
   
   
   
   
   
extends NotificationBroadcasterSupport
implements TimerMBean, MBeanRegistration

提供对计时器 MBean 的实现。计时器 MBean 将在指定的时间发出警告,以唤醒所有注册的侦听器来接收计时器通知。

此类管理一个过期的计时器通知列表。这是一种允许用户根据需要任意添加/移除通知的方法。当计时器发出计时器通知并过时后,会将该通知自动从计时器通知列表中移除。
可以将其他计时器通知添加到常规重复发送的通知中。

注:

  1. 在调用 addNotification 方法之前的所有通知都将被忽略,并且不考虑 sendPastNotifications 标志。
  2. 当发送计时器通知时,计时器将更新通知序列号,而不考虑通知类型。
  3. 计时器服务依赖于加载 Timer 类的主机的系统日期。如果侦听器主机具有不同的系统日期,则侦听器可能会不合时宜地接收到通知。为了避免此类问题,要同步所有需要计时的主机的系统日期。
  4. 定期通知的默认行为是固定延迟执行,这一点已在 Timer 中指定。为了使用固定速率执行,要使用重载的 addNotification(String, String, Object, Date, long, long, boolean) 方法。
  5. 可能会在同一线程中执行所有这些通知侦听器。因此,必须快速执行以避免阻止其他侦听器或者打乱固定延迟执行的规律。请参见 NotificationBroadcasterSupport

从以下版本开始:
1.5

字段摘要
static longONE_DAY
          一天内的毫秒数。
static longONE_HOUR
          一小时内的毫秒数。
static longONE_MINUTE
          一分钟内的毫秒数。
static longONE_SECOND
          一秒钟内的毫秒数。
static longONE_WEEK
          一周内的毫秒数。
 
构造方法摘要
Timer()
          默认的构造方法。
 
方法摘要
 IntegeraddNotification(String type, String message, Object userData, Date date)
          创建具有指定 typemessageuserData 的新计时器通知,并将其插入到带有给定日期以及 null 时段和出现数量的通知列表中。
 IntegeraddNotification(String type, String message, Object userData, Date date, long period)
          创建具有指定 typemessageuserData 的新计时器通知,并将其插入到带有给定日期和时段,以及 null 出现数量的通知列表中。
 IntegeraddNotification(String type, String message, Object userData, Date date, long period, long nbOccurences)
          创建具有指定 typemessageuserData 的新计时器通知,并将其插入到带有给定日期、时段和出现数量的通知列表中。
 IntegeraddNotification(String type, String message, Object userData, Date date, long period, long nbOccurences, boolean fixedRate)
          创建具有指定 typemessageuserData 的新计时器通知,并将其插入到带有给定日期、时段和出现数量的通知列表中。
 VectorgetAllNotificationIDs()
          获得所有在通知列表中注册的计时器通知标识符。
 DategetDate(Integer id)
          获得与计时器通知关联的日期的一个副本。
 BooleangetFixedRate(Integer id)
          获得此种标志的一个副本:该标志指示是以固定延迟 方式执行定期通知,还是以固定速率 方式执行。
 intgetNbNotifications()
          获得在通知列表中注册的计时器通知数。
 LonggetNbOccurences(Integer id)
          获得与计时器通知关联的剩余出现数量的一个副本。
 VectorgetNotificationIDs(String type)
          获得所有与指定类型对应的计时器通知的标识符。
 MBeanNotificationInfo[]getNotificationInfo()
          返回一个数组,指示此 MBean 可能发送的每个通知的 Java 类名和通知类型。
 StringgetNotificationMessage(Integer id)
          获得与指定的标识符对应的计时器通知的详细消息。
 StringgetNotificationType(Integer id)
          获得与指定的标识符对应的计时器通知类型。
 ObjectgetNotificationUserData(Integer id)
          获得与指定的标识符对应的计时器通知用户数据对象。
 LonggetPeriod(Integer id)
          获得与计时器通知关联的时段(以毫秒为单位)的一个副本。
 booleangetSendPastNotifications()
          获得一个指示计时器是否发送过期通知的标志。
 booleanisActive()
          测试计时器 MBean 是否处于激活状态。
 booleanisEmpty()
          测试计时器通知列表是否为空。
 voidpostDeregister()
          允许计时器 MBean 在 MBean 服务器注销它之后执行任何所需的操作。
 voidpostRegister(Boolean registrationDone)
          允许计时器 MBean 在 MBean 服务器中注册后或注册失败后执行任何所需的操作。
 voidpreDeregister()
          允许计时器 MBean 在 MBean 服务器注销它之前执行任何所需的操作。
 ObjectNamepreRegister(MBeanServer server, ObjectName name)
          允许计时器 MBean 在 MBean 服务器中注册之前执行任何所需的操作。
 voidremoveAllNotifications()
          从通知列表中删除所有的计时器通知并重置用来更新计时器通知标识符的计数器。
 voidremoveNotification(Integer id)
          从通知列表中移除与指定的标识符对应的计时器通知。
 voidremoveNotifications(String type)
          从通知列表中移除与指定的类型对应的所有计时器通知。
 voidsetSendPastNotifications(boolean value)
          设置指示计时器是否发送过期通知的标志。
 voidstart()
          启动计时器。
 voidstop()
          停止计时器。
 
从类 javax.management.NotificationBroadcasterSupport 继承的方法
addNotificationListener, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

ONE_SECOND

public static final long ONE_SECOND
一秒钟内的毫秒数。addNotification 方法的有用常量。

另请参见:
常量字段值

ONE_MINUTE

public static final long ONE_MINUTE
一分钟内的毫秒数。addNotification 方法的有用常量。

另请参见:
常量字段值

ONE_HOUR

public static final long ONE_HOUR
一小时内的毫秒数。addNotification 方法的有用常量。

另请参见:
常量字段值

ONE_DAY

public static final long ONE_DAY
一天内的毫秒数。addNotification 方法的有用常量。

另请参见:
常量字段值

ONE_WEEK

public static final long ONE_WEEK
一周内的毫秒数。addNotification 方法的有用常量。

另请参见:
常量字段值
构造方法详细信息

Timer

public Timer()
默认的构造方法。

方法详细信息

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
允许计时器 MBean 在 MBean 服务器中注册之前执行任何所需的操作。

未在此上下文中使用。

指定者:
接口 MBeanRegistration 中的 preRegister
参数:
server - 将在其中注册计时器 MBean 的 MBean 服务器。
name - 计时器 MBean 的对象名。
返回:
已注册的计时器 MBean 的名称。
抛出:
Exception

postRegister

public void postRegister(Boolean registrationDone)
允许计时器 MBean 在 MBean 服务器中注册后或注册失败后执行任何所需的操作。

未在此上下文中使用。

指定者:
接口 MBeanRegistration 中的 postRegister
参数:
registrationDone - 指示该 MBean 是否已在 MBean 服务器中成功注册。false 值意味着注册阶段已失败。

preDeregister

public void preDeregister()
                   throws Exception
允许计时器 MBean 在 MBean 服务器注销它之前执行任何所需的操作。

停止计时器。

指定者:
接口 MBeanRegistration 中的 preDeregister
抛出:
Exception