在jboss启动时加载class方法(定时操作)

一.jboss启动时加载class方法

A. 编写class,要import org.jboss.varia.scheduler.Schedulable包,此包在%JBOSS_DISC%/server/all/lib目录下,同时要把编译好的class(压成包)放在%JBOSS_DISC%/server/all/lib目录下,以便能加载。

B.修改%JBOSS_DISC%/server/all/conf/jboss-service.xml文件

 

添加以下相似文字:

<!--============================================================ -->

<!-- Scheduler Initialization 定时操作                                                                      -->

<!--============================================================ -->

  <mbean code="org.jboss.varia.scheduler.Scheduler"

name="jboss. piosan.util:service=Scheduler">

<attribute name="StartAtStartup">true</attribute>

<attribute name="SchedulableClass">com.piosan.util.PiosanTimer</attribute>

<attribute name="SchedulableArguments">TheName,123456789</attribute>

<attribute name="SchedulableArgumentTypes">java.lang.String,long</attribute>

<attribute name="InitialStartDate">NOW</attribute>

<attribute name="SchedulePeriod">1000</attribute>

<attribute name="InitialRepetitions">-1</attribute>

   </mbean>

<!—name为任意但唯一,com.piosan.util.PiosanTimerclass -->

<!—SchedulableArguments的值为传递参数,这里为两个参数,theNameString型,123456789long,SchedulableArgumentTypes中体现了 -->

<!—SchedulePeriod 的值为每隔1秒操作一次 -->

 

C. 附上PiosanTimer.java源代码例子

/*

 * Created on 2003-11-6

 *

 * To change the template for this generated file go to

 * Window - Preferences - Java - Code Generation - Code and Comments

 */

package com.util;

 

import java.util.Date;

import org.jboss.varia.scheduler.*;

public class PiosanTimer implements Schedulable {

  private String name;

  private long value;

 

  public PiosanTimer(String name,long value)

  {

    this.name = name;

    this.value = value;

    System.out.println("name="+name+"  value="+value);

    

  }

 

  /**

  会自动执行此函数,

  */

public void perform(Date now,long remainingRepetitions)

  {

    System.out.println("perform,now:"+now+

    ",remainingRepetitions: "+remainingRepetitions+

    ",name: "+name+ ",value: "+value);

  }

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值