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

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

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

    kapok

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

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

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

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

    public interface TimedObject {

          public void ejbTimeout(Timer timer) ;

    }

    例如:當(dāng)時(shí)間到,EntityBean執(zhí)行數(shù)據(jù)更新操作

    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是一個(gè)回調(diào)方法,執(zhí)行具體的商業(yè)邏輯,那么怎樣設(shè)置什么時(shí)間觸發(fā)這個(gè)方法呢,我們利用javax.ejb.TimerSevice。該對象我們可以從EJBContext中獲得該對象實(shí)例。為此我們在上面的例子中添加一個(gè)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中提供了設(shè)置了Timer的方法,包括設(shè)置一個(gè)時(shí)間點(diǎn)(ejbTimedOut方法運(yùn)行一次)和時(shí)間間隔(ejbTimedOut方法運(yùn)行多次)。另外,它還提供了getTimer()的方法,該方法返回一個(gè)Collection,里面包含了已經(jīng)注冊了的所有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方法用來取消一個(gè)已經(jīng)無效的Timer(時(shí)間點(diǎn)已經(jīng)過去)。

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

    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,當(dāng)createTimer如果在Transaction中,如果該transaction rollback則創(chuàng)建的Timer也會取消。





    posted on 2005-03-29 10:50 笨笨 閱讀(451) 評論(0)  編輯  收藏 所屬分類: J2EEALL
    主站蜘蛛池模板: 亚洲国产成人精品无码区在线观看| 亚洲男人天堂2017| 在线观看日本亚洲一区| 老汉精品免费AV在线播放| 国产成人免费a在线视频色戒| 99热亚洲色精品国产88| 亚洲乱人伦中文字幕无码| 9久热精品免费观看视频| 成人性生交视频免费观看| 国产亚洲av片在线观看播放| 国产乱子伦精品免费视频| 亚洲国产成人片在线观看无码| jizz免费观看| 亚洲成年轻人电影网站www| 中文字幕乱码亚洲无线三区| 午夜视频免费成人| 1000部拍拍拍18免费网站| 亚洲国产午夜精品理论片在线播放| 国产免费观看网站| 国产特黄一级一片免费| 亚洲AV无码久久精品成人| 国内精品乱码卡1卡2卡3免费| 亚洲视频.com| 亚洲AV综合色区无码一区爱AV| 国产精品玖玖美女张开腿让男人桶爽免费看| 久久精品国产精品亚洲艾| 国产在线精品免费aaa片| AV在线亚洲男人的天堂| 免费国产99久久久香蕉| 亚洲av无码乱码国产精品| 日韩精品无码区免费专区| 亚洲色无码一区二区三区| 一区二区在线免费视频| 亚洲高清不卡视频| 国产伦精品一区二区三区免费下载 | 全部免费毛片在线播放| 亚洲激情在线观看| 免费99热在线观看| 香港特级三A毛片免费观看| 国产一区二区三区无码免费| 免费久久人人爽人人爽av|