【问题标题】:JBoss Task scheduling: pass argument to methodJBoss 任务调度:将参数传递给方法
【发布时间】:2010-07-14 18:41:28
【问题描述】:

我正在尝试让调度程序在 JBoss 中工作为 5。

到目前为止,我已经创建了自己的 MBean(它可以工作)并且我创建了这样的调度程序:

<mbean code="org.jboss.varia.scheduler.Scheduler"
          name=":service=Scheduler,name=SchedulableMBeanExample">
  <depends>user:service=Print</depends>
  <attribute name="StartAtStartup">true</attribute>
  <attribute name="SchedulableMBean">user:service=Print</attribute>
  <attribute name="SchedulableMBeanMethod">print(java.lang.String)</attribute>
  <attribute name="InitialStartDate">NOW</attribute>
  <attribute name="SchedulePeriod">10000</attribute>
  <attribute name="InitialRepetitions">10</attribute>
  <attribute name="FixedRate">true</attribute></mbean>

它有效,但主要问题是如何指定要作为参数传递给我的方法的字符串?

我已经搜索过,但我发现唯一更接近的是这个属性:“SchedulableArguments”,但这仅适用于构造函数。

感谢你们的帮助。

洛朗。

【问题讨论】:

    标签: java jboss scheduling jboss5.x


    【解决方案1】:

    在 JBoss 中安装 MBean 后,您可以通过 JBoss jmx-console 配置 MBean 参数来配置 JBoss。

    请参阅 JBoss wiki 中的这篇文章:ExampleHelloWorldService

    【讨论】:

      【解决方案2】:

      你已经成功了一半;你得到了正确的属性——SchedulableMBeanMethod——它允许参数列表,但只有特定的参数。根据jboss 4 guide,您的参数选项是:

      • NOTIFICATION 将被定时器通知实例 (javax.management.Notification) 替换

      • 将替换为通知调用日期的 DATE (java.util.Date)

      • REPETITIONS 将替换为剩余重复次数(长)

      • SCHEDULER_NAME 将被调度程序的 ObjectName 替换

      • 调度程序将设置为 null 的任何完全限定的类名。

        如果您需要传递任何其他内容,我认为您最好的选择是向您的 mbean 添加一个方法,只是为了计算并将参数传递给您的工作函数。

      猜测你想打印当前日期,你可以设置:

        <attribute name="SchedulableMBeanMethod">scheduledPrint(DATE)</attribute>
      

      并定义 scheduledPrint 以格式化日期字符串并调用您的 print 方法。

      【讨论】:

        猜你喜欢
        • 2018-01-04
        • 1970-01-01
        • 1970-01-01
        • 2015-04-16
        • 1970-01-01
        • 2015-08-17
        • 2019-07-03
        • 1970-01-01
        • 2017-06-06
        相关资源
        最近更新 更多