<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    kapok

    垃圾桶,嘿嘿,我藏的這么深你們還能找到啊,真牛!

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      455 隨筆 :: 0 文章 :: 76 評論 :: 0 Trackbacks

    http://computer.mblogger.cn/sammi_tea
    http://www.weste.net/html/200310/20031029QBI124658.html

    使用
    Timer Service 可以在某一指定時間到了,或周期性Schedule開始時,通知EJB執行指定操作。為了使用Timer ServiceEJB需要實現javax.ejb.TimedObject接口。

    public interface TimedObject {

          public void ejbTimeout(Timer timer) ;

    }

    例如:當時間到,EntityBean執行數據更新操作

    public abstract class ShipBean implements javax.ejb.EntityBean, javax.ejb.TimedOut {

        javax.ejb.EntityContext ejbContext;

        public void setEntityContext(javax.ejb.EntityContext ctxt){

             ejbContext = ctxt;

        }

        public void ejbTimedout(javax.ejb.Timer timer) {

           // business logic for timer goes here

    }

    。。。。

    從上面的使用例子看ejbTimedout是一個回調方法,執行具體的商業邏輯,那么怎樣設置什么時間觸發這個方法呢,我們利用javax.ejb.TimerSevice。該對象我們可以從EJBContext中獲得該對象實例。為此我們在上面的例子中添加一個ejbHome方法scheduleMaintenance

    public inteface ShipBeanHome implements javax.ejb.EJBHome {

    ShipBeanRemote create() throws CreateException, RemoteException;

    void scheduleMaintenance(String desc, Date scheduleDate) throws RemoteException;

    ……

    }

     

    public abstract class ShipBean implements javax.ejb.EntityBean, javax.ejb.TimedOut {

        javax.ejb.EntityContext ejbContext;

        public void setEntityContext(javax.ejb.EntityContext ctxt){

             ejbContext = ctxt;

    }

    public void ejbScheduleMaintenance(String desc, Date scheduleDate) {

          TimerService service = ejbContext.getTimerService();

    Service.createTime(scheduleDate, desc);

    }

        public void ejbTimedout(javax.ejb.Timer timer) {

           // business logic for timer goes here

    }

     

    TimerService中提供了設置了Timer的方法,包括設置一個時間點(ejbTimedOut方法運行一次)和時間間隔(ejbTimedOut方法運行多次)。另外,它還提供了getTimer()的方法,該方法返回一個Collection,里面包含了已經注冊了的所有Timer對象。

     

    Timer接口

    public interface Timer {

        // Cause the timer and all its associated expiration notifications to be canceled

        public void cancel() 

             throws IllegalStateException,NoSuchObjectLocalException,EJBException;

        // Get the information associated with the timer at the time of creation.

        public java.io.Serializable getInfo()

             throws IllegalStateException,NoSuchObjectLocalException,EJBException;

        // Get the point in time at which the next timer expiration is scheduled to occur.

        public java.util.Date getNextTimeout()

             throws IllegalStateException,NoSuchObjectLocalException,EJBException;

        // Get the number of milliseconds that will elapse before the next scheduled timer expiration

        public long getTimeRemaining()

             throws IllegalStateException,NoSuchObjectLocalException,EJBException;

        //Get a serializable handle to the timer.

        public TimerHandle getHandle()

             throws IllegalStateException,NoSuchObjectLocalException,EJBException;

    }

    Cancel方法用來取消一個已經無效的Timer(時間點已經過去)。

    GetInfo方法獲得一個Timer的相關信息,這些信息在createTimer時作為參數和Timer聯系在一起。在前面的例子中,為了防止客戶胡亂調用ejbHome方法scheduleMaintenance,我們可以為每一個設定的時間添加一個唯一編號。修改后的代碼如下:

    public class MaintenanceItem implements java.io.Serializable {

        private long maintenanceItemNumber;

        private String description;

        public MaintenanceItem(long min, String desc){

            maintenanceItemNumber = min;

            description = desc;

        }

        public long getMIN(){

            return maintenanceItemNumber;

        }

        public String getDescription(){

            return description;

        }

    public void scheduleMaintenance(MaintenanceItem maintenanceItem, Date dateOfTest){

            TimerService timerService = ejbContext.getTimerService();

            java.util.Iterator timers = timerService.getTimers().iterator();

            while( timers.hasNext() ){

                    javax.ejb.Timer timer = (javax.ejb.Timer) timers.next();

                    String timerMainItem = (MaintenanceItem) timer.getInfo();

                    if( maintenanceItem.getMIN() == timerMainItem.getMIN() )

                         timer.cancel();

                    }

            }

            timerService.createTimer( dateOfText, maintenanceItem);

        }

    TimerServiceTransaction

    TimerService可以參與Transaction,當createTimer如果在Transaction中,如果該transaction rollback則創建的Timer也會取消。





    posted on 2005-03-29 10:50 笨笨 閱讀(451) 評論(0)  編輯  收藏 所屬分類: J2EEALL
    主站蜘蛛池模板: 亚洲一区无码中文字幕 | 狼群影院在线观看免费观看直播| 亚洲AV综合色区无码另类小说| 久章草在线精品视频免费观看| 日韩亚洲国产高清免费视频| 亚洲国产精品人人做人人爱| 久久国产色AV免费看| 亚洲精品无码不卡在线播放| 亚洲精品无码mv在线观看网站| 99久久99这里只有免费费精品 | 2020国产精品亚洲综合网 | 亚洲aⅴ无码专区在线观看春色| 亚洲无线码一区二区三区| 999在线视频精品免费播放观看| 男女超爽视频免费播放| 亚洲国产成人久久综合一| 国产成人免费全部网站| 午夜免费福利片观看| 国产亚洲福利一区二区免费看| 亚洲一区综合在线播放| 又爽又黄无遮挡高清免费视频| 99国产精品免费观看视频| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 亚洲午夜久久久久久久久久| 久久精品免费一区二区喷潮| 国产中文字幕在线免费观看| 亚洲欧美不卡高清在线| 2022年亚洲午夜一区二区福利 | 亚洲精品一卡2卡3卡三卡四卡| 亚洲精品tv久久久久| 成人片黄网站A毛片免费| 日韩免费电影网站| 麻豆69堂免费视频| 亚洲日本国产综合高清| 亚洲日韩区在线电影| 77777亚洲午夜久久多人| 国产成人涩涩涩视频在线观看免费| 1000部无遮挡拍拍拍免费视频观看| 国产成人自产拍免费视频| 成a人片亚洲日本久久| 久久精品亚洲AV久久久无码|