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

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

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

    A "Hello" program on EJB3 with Jboss server 4.2.2GA (PART 3) - EJB3 Timer service.

        Timer service in EJB3 with anotation is fairly simple, I give you an example as follow, and it's really simple and self-explanation:
     1 package com.ramon.expejb3.session.impl;
     2 
     3 import javax.annotation.Resource;
     4 import javax.ejb.Stateless;
     5 import javax.ejb.Timeout;
     6 import javax.ejb.Timer;
     7 import javax.ejb.TimerService;
     8 
     9 import com.ramon.expejb3.session.Greeting;
    10 
    11 @Stateless(name = "Greeting")
    12 public class GreetingBean implements Greeting {
    13     
    14     @Resource
    15     TimerService ts;
    16 
    17     /* (non-Javadoc)
    18      * @see com.ramon.expejb3.session.Greeting#greeting(java.lang.String)
    19      */
    20     public void greeting(String name) {
    21         System.out.println("Hello " + name + ".");
    22         ts.createTimer(1 * 10005 * 1000, name);
    23         System.out.println("Create timer for " + name + ".");
    24     }
    25     
    26     @Timeout
    27     public void timeout(Timer timer) {
    28         String name = (String)timer.getInfo();
    29         System.out.println(name + " TIME OUT.");
    30         //timer.cancel();
    31     }
    32 }
    33
        It's the "GreetingBean" I introduced in part one of this series article with TimerService injected, @Resource anotation inject the time service we want, it's totally free which is supported by the J2EE container that means we do not need any further steps to get the powerful schedule service. In the line 22, I crate a new timer, I think this could be more fit if it was called Task instead, there are several "createTimer" methods with different parameters, the one I used here describe the task should be execute 1 second delay and every 5 second one time in the future, the third parameter can be anything you want to pass in to the task, it can be get back use method Timer.getInfo() like line 28 does here.
        Another important anotation here is the @Timeout anotation, this anotation tell container which method will be called when timeout for this task to be executed, you can only specify one timeout method for each Bean, if there is no @Timeout anotation at all, you will get some exception like "No timeout method specified" in Jboss server. Something funny here is that you should mark the timeout method as "public", otherwise, you will get the same error as no timeout method does, I do NOT think it's necessary, because the time out method should only be called by the container, "private" signature is enought for that, with "private" signature container still has the right to access this method with java reflection, nevertheless timer service in EJB3 is still a good tools for use.
        I summarize what good/bad for timer service in EJB3 as follow:
        Good news:
    •     It's free, it's supported by the EJB container.
    •     It's portable, it's supported by the EJB container as specified in EJB3 specification.
    •     It's easy to use, no need to learn more.
        Bad news:
    •     The feature of EJB3 timer sevice is not as powerful as some third party timer service such as Quartz, but it's enough with EJB3 for ordinary daily job.
    •     There is no UI for you to monitor the timer you created.

    posted on 2008-03-26 13:30 Find it, try it, experience it 閱讀(1186) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2008年3月>
    2425262728291
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    導航

    統計

    公告

    If there is any question you have, please don't hesitate, let me know ASAP, you can find me at kenees@gmail.com or QQ: 9808873, hope to make friends with you ;)

    常用鏈接

    留言簿(1)

    隨筆檔案

    文章檔案

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲大尺度无码无码专线一区| 亚洲日本一区二区| 亚洲乱码无人区卡1卡2卡3| 2021精品国产品免费观看| 亚洲电影一区二区三区| 无码国产精品一区二区免费vr| 亚洲色WWW成人永久网址| 国产无遮挡又黄又爽免费网站| 亚洲人成网站在线观看播放| 青柠影视在线观看免费高清| 亚洲大尺度无码无码专区| 四虎国产成人永久精品免费| 亚洲网红精品大秀在线观看| 韩国免费一级成人毛片| 亚洲日韩精品A∨片无码加勒比| 黑人粗长大战亚洲女2021国产精品成人免费视频| 国产99在线|亚洲| 国产在线a不卡免费视频| 美女黄色毛片免费看| 国产综合精品久久亚洲| 在线播放免费人成毛片乱码| 亚洲精品视频在线观看视频| 97人伦色伦成人免费视频| 看成年女人免费午夜视频| 国产亚洲精彩视频| 中文字幕亚洲日韩无线码| 亚洲熟伦熟女专区hd高清| 免费国产不卡午夜福在线| 亚洲18在线天美| 婷婷亚洲天堂影院| 久久99热精品免费观看动漫| 亚洲欧洲日本在线观看 | 成年女人免费视频播放体验区| 色偷偷噜噜噜亚洲男人| av在线亚洲欧洲日产一区二区| 日本免费一区二区久久人人澡| 丁香婷婷亚洲六月综合色| 国产成人高清亚洲| 国内精品乱码卡1卡2卡3免费| 日韩在线一区二区三区免费视频| 亚洲色欲色欲综合网站|