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

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

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

    Oracle神諭

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      284 隨筆 :: 9 文章 :: 106 評論 :: 0 Trackbacks

    #

    (org.jbpm.identity)身份包包含有如下幾個類:
    一、Entity 實體類:這個類作為users<用戶>groups<組>和memberships<成員>的超類,用來管理名稱和權限的增加刪除和獲取。其中用到了jdk的Permission類。目前還不知道這個對具體權限的控制有什么作用?
    二、Group組類:這個類是Entity的繼承子類,這個類主要用于區分層次組、安全角色和其他。  
      (1)主要包含以下幾個Filed:
         protected String type = null;
         protected Group parent = null; //父就是自己
         protected Set children = null; //子是一個集合,其中的元素也是Group
         protected Set memberships = null; //會員
       (2)JBpm的類內部方法的命名還是很不錯的:
        public Set getUsersForMembershipName(String membershipName) 很容易理解為通過membershipName來獲得所有的用戶。 這個內不僅僅是簡單的JavaBean的setter和getter,而是進行一些引申的操作,例如獲取用戶以及addXXX等操作。
       (3)與之相對應的hibernate Mapping文件Group.hbm.xml其中也有幾個地方,值得注意,其實這個在Jbpm中是大量使用的:
               table="JBPM_ID_GROUP"
             discriminator-value="G">
        ....
     
      這里表示的是在JBPM_ID_GROUP表中的CLASS_字段等于G的為Group的影射對象。這里我們在使用一個表的不同類型(一個字段對應不同的值)就可以表示不同的類型對象。這一點很值得我們學習的。其他值得我們關注的是它采用的集合類型的操作方式,在我們以前的開發中這種做法并值得采用的。
    三、Membership成員類:它是用戶和組之間的一個聯系的橋梁。會員的名稱代表角色的名稱。一個會員可能是一個組織的位置,所以權限往往于會員聯系。會員的名字能用來做角色的名字。不同的會員來擔當不同的角色。
    protected  String role = null;
    protected Group group = null;
    protected User user = null;
     這個類沒有采用傳統的構造子復用的方式,而是用很了很多的create()方法,有些方法讓人感覺有些茫然不知所措,不過直接相關的代碼,也就明白了。
      其中影射文件也使用了discriminator(鑒別者)的功能,以及many-to-one和set集合的做法
    四、User類:包含有三個字段:password email  以及Set memeberships。
      以下是通過兩種方式獲得Groups的方法,一個是通過組的類別,一種是通過成員名稱(角色名稱)
      public Set getGroupsForGroupType(String groupType)
      public Set getGroupsForMembershipName(String membershipName)

      通過觀察,我們發現這里其實有以下幾個對象:Entity Group Memebership User Permission。其中Group、Memebership、User都是Entity都是子類和父類的關系。Entity和Permission是一對多的關系,表示一個實體擁有各種不同的權限,同樣其他的Group等子類,也與Permission都是一對多的關系。Group 和Memeber是一對多的,一個組具有不同的角色(成員)。Membership與User和Group是多對一的關系。User和Membership之間是一對多的關系。

    其中涉及的表有:
    jbpm_id_group;
    jbpm_id_membership;
    jbpm_id_user;

    posted @ 2005-09-17 21:33 java世界暢談 閱讀(1251) | 評論 (0)編輯 收藏

    今天在看Jbpm的源代碼中,發現其中的Hibernate中的PO的序列化對象基本上都有一個serialVersionUID的一個私有對象,就上網查找了一部分資料。
    http://www.javapractices.com/Topic45.cjp
    Guidelines for serialVersionUID : (serialVersionUID的指導綱要)

    • always include it as a field, for example: "private static final long serialVersionUID = 7526472295622776147L; " include this field even in the first version of the class, as a reminder(提示) of its importance
    • do not change the value of this field in future versions, unless you are knowingly(老練地) making changes to the class which will render(使..變成) it incompatible(不相容的) with old serialized objects
    • new versions of Serializable classes may or may not be able to read old serialized objects;  it depends upon the nature of the change; provide a pointer to Sun's guidelines for what constitutes a compatible(兼容地) change, as a convenience to future maintainers
    posted @ 2005-09-17 21:15 java世界暢談 閱讀(505) | 評論 (0)編輯 收藏

     在網站中經常需要進行在線人數的統計。過去的一般做法是結合登錄和退出功能,即當用戶輸入用戶名密碼進行登錄的時候計數器加1,然后當用戶點擊退出按鈕退出系統的時候計數器減1。這種處理方式存在一些缺點,例如:用戶正常登錄后,可能會忘記點擊退出按鈕,而直接關閉瀏覽器,導致計數器減1的操作沒有及時執行;網站上還經常有一些內容是不需要登錄就可以訪問的,在這種情況下也無法使用上面的方法進行在線人數統計。
      我們可以利用Servlet規范中定義的事件監聽器(Listener)來解決這個問題,實現更準確的在線人數統計功能。對每一個正在訪問的用戶,J2EE應用服務器會為其建立一個對應的HttpSession對象。當一個瀏覽器第一次訪問網站的時候,J2EE應用服務器會新建一個HttpSession對象,并觸發HttpSession創建事件,如果注冊了HttpSessionListener事件監聽器,則會調用HttpSessionListener事件監聽器的sessionCreated方法。相反,當這個瀏覽器訪問結束超時的時候,J2EE應用服務器會銷毀相應的HttpSession對象,觸發HttpSession銷毀事件,同時調用所注冊HttpSessionListener事件監聽器的sessionDestroyed方法。
      可見,對應于一個用戶訪問的開始和結束,相應的有sessionCreated方法和sessionDestroyed方法執行。這樣,我們只需要在HttpSessionListener實現類的sessionCreated方法中讓計數器加1,在sessionDestroyed方法中讓計數器減1,就輕松實現了網站在線人數的統計功能。
      下面就是利用HttpSessionListener實現在線人數統計的一個例子,這個例子已經在中創軟件的J2EE應用服務器InforWeb中測試通過。
      首先,編寫一個簡單的計數器,代碼如下:
    1. package gongfei.cmc.articles.onlinecounter;
    2. public class OnlineCounter {
    3.     private static long online = 0;    
    4.     public static long getOnline() {
    5.         return online;
    6.     }    
    7.     public static void raise(){
    8.         online++;
    9.     } 
    10.     public static void reduce(){
    11.         online--;
    12.    }
    13. }

      然后,編寫HttpSessionListener實現類,在這個實現類的sessionCreated方法中調用OnlineCounter的raise方法,在sessionDestroyed方法中調用OnlineCounter的reduce方法,代碼如下:
    1. package gongfei.cmc.articles.onlinecounter;
    2. import javax.servlet.http.HttpSessionEvent;
    3. import javax.servlet.http.HttpSessionListener;
    4. public class OnlineCounterListener implements HttpSessionListener {
    5.     public void sessionCreated(HttpSessionEvent hse) {
    6.         OnlineCounter.raise();
    7.     }
    8.     public void sessionDestroyed(HttpSessionEvent hse) {
    9.         OnlineCounter.reduce();
    10.     }
    11. }

      再然后,把這個HttpSessionListener實現類注冊到網站應用中,也就是在網站應用的web.xml中加入如下內容:
    1. <web-app>
    2.     ……
    3.     <listener>
    4.         <listener-class>
    5.             gongfei.cmc.articles.example.OnlineCounterListener
    6.         </listener-class>
    7.     </listener>
    8.     ……
    9. </web-app>


    原文地址:http://www.javaresearch.org/article/showarticle.jsp?column=106&thread=18541

    posted @ 2005-09-12 16:06 java世界暢談 閱讀(1014) | 評論 (1)編輯 收藏

      很長時間也沒有下Blog了,今天是周末。在家里休息,就隨手寫點東西了。這一陣是比較忙碌,時間都過的很是緊湊,沒有多余的時間來寫blog,也沒有學習什么新的東西。不過因為,公司現在采用JDK5.0的語法,琢磨了枚舉類型和泛型,也看看了不定參數已經自動裝箱等等功能。有些功能確實不錯,不過一下子還是不太適應。
      自動裝拆箱不錯,基本數據類型和java類型可以自己進行轉換,不需要特意進行轉換。
      枚舉感覺用得不是很多的,當然在特定環境下,這個還是有些作用的。
      其實很多時間都在琢磨泛型。這東西很是不錯,以后不用在一次次進行轉型,不過現在還在新老代碼的更替中,新老代碼同時并存。
      不定參數也有點意思。以后不用丟set或者map等等接口了。

    posted @ 2005-09-11 11:43 java世界暢談 閱讀(173) | 評論 (1)編輯 收藏

    About
    --------------------------------------------------------------------------------

    What is it?  它是什么?

    Mantis is a web-based bugtracking system. It is written in the PHP scripting language and

    requires the MySQL database and a webserver. Mantis has been installed on Windows, MacOS,

    OS/2, and a variety of Unix operating systems. Almost any web browser should be able to

    function as a client. It is released under the terms of the GNU General Public License

    (GPL).
    Nantis 是一個基于web bug追蹤系統。它使用php腳本語言和需要Mysql 數據庫和一個web服務器。Mantis

    已經被安裝在Windows、MacOS、OS/2和各種各樣Unix操作系統中。幾乎所有的web瀏覽器應該可以做為一

    個客戶端功能。它被在GNU通用公共license(GNU)下發布。

    Mantis is free to use and modify. It is free to redistribute as long as you abide by the
    distribution terms of the GPL.

    Mantis是免費使用和修改的。它是在GPL原則下可以被重新修改分配的。

    History 歷史

    Mantis started as an internal bug tracking tool for a pet project (video game). Good, free

    packages were lacking at the time so a bugtracker was written. Since then, Mantis has been

    totally re-written and make it available to the public.

    Mantis開始作為一個為pet項目(視頻游戲)的內部bug追蹤工具。免費的包缺少在時間,所以bug追蹤被

    寫出。從那以后,mantis被重新編寫并且將它公布與眾。

    Goals 目標

    The goals for this project are to produce and maintain a lightweight and simple bugtracking

    system. Additions of complexity and/or features are modular and configurable so that users

    can be shielded from unwanted clutter.

    這個項目的目標是產生和維護一個高亮度并且簡單的bug追蹤系統。復雜的附加特征被模塊化并且被注冊

    這樣,用戶可以避免不想要的混亂。

    The product is designed to be easily modifiable, customizable, and upgradeable. Anyone with

    intermediate PHP and MySQL experience should be able to customize Mantis to suit their

    needs.

    這個產品被設計成很容易修改,可定制、和可升級的。伴隨Php和MySQL經驗的任何人應該可以定制Mantis

    來滿足他們的需要。

    Features and Benefits 特性和用處


    Free  免費
    Easy installation  容易安裝
    Web based   基于web
    Platform independent  平臺獨立
    Multiple projects   多項目
    Multiple languages  多語言
    Emailing     郵件
    Simple Search  簡單搜索
    Viewing filters   過濾顯示
    PHP    php

     

    Upcoming Features 將來的特征

    Check the Roadmap for a more detailed and sometimes up to date list of items.

    Versioning

    The release numbering convention used is major.minor.micro (eg. 0.18.2).

    Major - Indicates a very large change in the core package. Rewrites or major milestones.
    Minor - Significant amount of feature addition/modification.
    Micro - Usually bug fixes or minor features
    How to Help


    Report real bugs to the Development Bugtracker
    Suggest (reasonable) features
    Contribute code or tell us where to look.
    Let us know if you find it useful. We won't publish the information without permission, but

    we appreciate the feedback!

    posted @ 2005-08-05 17:30 java世界暢談 閱讀(1165) | 評論 (1)編輯 收藏

    Sending Email with Spring mail abstraction layer
    使用Spring郵件抽象層發送郵件:
    18.1. Introduction
    介紹
    Spring provides a higher level of abstraction for sending electronic mail which shields the user from the specifics of underlying mailing system and is responsible for a low level resource handling on behalf of the client.

    Spring 支持一個更高層的抽象用來發送電子郵件,它隱藏底層郵件系統的細節并且代表客戶端對低級別的控制 。

    18.2. Spring mail abstraction structure
    Spring郵件抽象結構
    The main package of Spring mail abstraction layer is org.springframework.mail package. It contains central interface for sending emails called MailSender and the value object which encapsulates properties of a simple mail such as from, to, cc, subject, text called SimpleMailMessage. This package also contains a hierarchy of checked exceptions which provide a higher level of abstraction over the lower level mail system exceptions with the root exception being MailException.Please refer to JavaDocs for more information on mail exception hierarchy.

    Sring郵件抽象層的主要包是:org.springframework.mail 包。它包含叫MailSender為發送郵件的核心接口和包含簡單郵件屬性例如from,to,cc,subject,text叫SimpleMailMessage的值對象. 這個包也包含一個檢查異常的層次,它支持一個更高級別的抽象超過低級別的郵件系統異常伴隨根異常存在MailException. 請參考JavaDocs為更多的信息雜郵件異常層次。

    Spring also provides a sub-interface of MailSender for specialized JavaMail features such as MIME messages, namely org.springframework.mail.javamail.JavaMailSender It also provides a callback interface for preparation of JavaMail MIME messages, namely org.springframework.mail.javamail.MimeMessagePreparator

    Spring也支持一個MailSender的專用于JavaMail特征例如MIME消息子接口,命名為org.springframework.javamail.JavaMailerSener。它也支持一個為JavaMail MIME信息的準備回調接口,命名為org.springframework.mail.JavaMail.MimeMessagePreparator.

    MailSender:

    public interface MailSender {

        /**
         * Send the given simple mail message.
         * @param simpleMessage message to send
         * @throws MailException in case of message, authentication, or send errors
         * 發送給定的簡單郵件信息
         * @參數 simpleMessage  發送的信息
         * @throws MailException 假設信息,證明或發送錯誤
         */
        
        public void send(SimpleMailMessage simpleMessage) throws MailException;

        /**
         * Send the given array of simple mail messages in batch.
         * @param simpleMessages messages to send
         * @throws MailException in case of message, authentication, or send errors
         */
        public void send(SimpleMailMessage[] simpleMessages) throws MailException;

    }

    JavaMailSender:

    public interface JavaMailSender extends MailSender {

        /**
         * Create a new JavaMail MimeMessage for the underlying JavaMail Session
         * of this sender. Needs to be called to create MimeMessage instances
         * that can be prepared by the client and passed to send(MimeMessage).
         * @return the new MimeMessage instance
         * @see #send(MimeMessage)
         * @see #send(MimeMessage[])
         * 創建一個新的JavaMail MimeMessage 為潛在的JavaMail的發送者的會話.
         * 需要被調用來創建MimeMessage實例,它可以被客戶準備并且被傳遞發送(MimeMessage).
         * @return 這個新的MimeMessage 實例
         * @see #send(Message)
         * @sess #send(MimeMessage[])
         */
        public MimeMessage createMimeMessage();

        /**
         * Send the given JavaMail MIME message.
         * The message needs to have been created with createMimeMessage.
         * @param mimeMessage message to send
         * @throws MailException in case of message, authentication, or send errors
         * @see #createMimeMessage
         */
        public void send(MimeMessage mimeMessage) throws MailException;

        /**
         * Send the given array of JavaMail MIME messages in batch.
         * The messages need to have been created with createMimeMessage.
         * @param mimeMessages messages to send
         * @throws MailException in case of message, authentication, or send errors
         * @see #createMimeMessage
         */
        public void send(MimeMessage[] mimeMessages) throws MailException;

        /**
         * Send the JavaMail MIME message prepared by the given MimeMessagePreparator.
         * Alternative way to prepare MimeMessage instances, instead of createMimeMessage
         * and send(MimeMessage) calls. Takes care of proper exception conversion.
         * @param mimeMessagePreparator the preparator to use
         * @throws MailException in case of message, authentication, or send errors
         */
        public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException;

        /**
         * Send the JavaMail MIME messages prepared by the given MimeMessagePreparators.
         * Alternative way to prepare MimeMessage instances, instead of createMimeMessage
         * and send(MimeMessage[]) calls. Takes care of proper exception conversion.
         * @param mimeMessagePreparators the preparator to use
         * @throws MailException in case of message, authentication, or send errors
         */
        public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException;

    }
    MimeMessagePreparator:

    public interface MimeMessagePreparator {

        /**
         * Prepare the given new MimeMessage instance.
         * @param mimeMessage the message to prepare
         * @throws MessagingException passing any exceptions thrown by MimeMessage
         * methods through for automatic conversion to the MailException hierarchy
         */
        void prepare(MimeMessage mimeMessage) throws MessagingException;

    }

    18.3. Using Spring mail abstraction
    使用Spring郵件抽象
    Let's assume there is a business interface called OrderManager
    讓我們假定這里有一個商業接口叫OrderManager

    public interface OrderManager {

        void placeOrder(Order order);
       
    }

    and there is a use case that says that an email message with order number would need to be generated and sent to a customer placing that order. So for this purpose we want to use MailSender and SimpleMailMessage
    并且這里有一個有用案例,可以說一個伴隨訂單編號的郵件信息將需要被產生并且發送給一個客戶處理這個訂單。所以為這個目的我們想要使用MailSender和SimpleMailSender.


    Please note that as usual, we work with interfaces in the business code and let Spring IoC container take care of wiring of all the collaborators for us.

    請注意照常,我們工作使用在商業代碼中的接口并且讓Spring Ioc 容器關心為我們的所有合作者。

    Here is the implementation of OrderManager
    這里是OrderManager的實現:

    import org.springframework.mail.MailException;
    import org.springframework.mail.MailSender;
    import org.springframework.mail.SimpleMailMessage;

    public class OrderManagerImpl implements OrderManager {

        private MailSender mailSender;
        private SimpleMailMessage message;

        public void setMailSender(MailSender mailSender) {
            this.mailSender = mailSender;
        }

        public void setMessage(SimpleMailMessage message) {
            this.message = message;
        }

        public void placeOrder(Order order) {

            //... * Do the business calculations....
            //... * Call the collaborators to persist the order

            //Create a thread safe "sandbox" of the message
            SimpleMailMessage msg = new SimpleMailMessage(this.message);
            msg.setTo(order.getCustomer().getEmailAddress());
            msg.setText(
                "Dear "
                    + order.getCustomer().getFirstName()
                    + order.getCustomer().getLastName()
                    + ", thank you for placing order. Your order number is "
                    + order.getOrderNumber());
            try{
                mailSender.send(msg);
            }
            catch(MailException ex) {
                //log it and go on
                System.err.println(ex.getMessage());           
            }
        }
    }
    Here is what the bean definitions for the code above would look like:
    這里是這個為這個以上代碼bean定義類似:

    <bean id="mailSender"
          class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host"><value>mail.mycompany.com</value></property>
    </bean>

    <bean id="mailMessage"
          class="org.springframework.mail.SimpleMailMessage">
        <property name="from"><value>customerservice@mycompany.com</value></property>
        <property name="subject"><value>Your order</value></property>
    </bean>

    <bean id="orderManager"
          class="com.mycompany.businessapp.support.OrderManagerImpl">
        <property name="mailSender"><ref bean="mailSender"/></property>
        <property name="message"><ref bean="mailMessage"/></property>
    </bean>
    Here is the implementation of OrderManager using MimeMessagePreparator callback interface. Please note that the mailSender property is of type JavaMailSender in this case in order to be able to use JavaMail MimeMessage:

    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;

    import javax.mail.internet.MimeMessage;
    import org.springframework.mail.MailException;
    import org.springframework.mail.javamail.JavaMailSender;
    import org.springframework.mail.javamail.MimeMessagePreparator;

    public class OrderManagerImpl implements OrderManager {
        private JavaMailSender mailSender;
       
        public void setMailSender(JavaMailSender mailSender) {
            this.mailSender = mailSender;
        }

        public void placeOrder(final Order order) {

            //... * Do the business calculations....
            //... * Call the collaborators to persist the order
           
           
            MimeMessagePreparator preparator = new MimeMessagePreparator() {
                public void prepare(MimeMessage mimeMessage) throws MessagingException {
                    mimeMessage.setRecipient(Message.RecipientType.TO,
                            new InternetAddress(order.getCustomer().getEmailAddress()));
                    mimeMessage.setFrom(new InternetAddress("mail@mycompany.com"));
                    mimeMessage.setText(
                        "Dear "
                            + order.getCustomer().getFirstName()
                            + order.getCustomer().getLastName()
                            + ", thank you for placing order. Your order number is "
                            + order.getOrderNumber());
                }
            };
            try{
                mailSender.send(preparator);
            }
            catch(MailException ex) {
                //log it and go on
                System.err.println(ex.getMessage());           
            }
        }
    }
    If you want to use JavaMail MimeMessage to the full power, the MimeMessagePreparator is available at your fingertips.
    如果你想使用JavaMail  MimeMessage來使得足夠強大,MimeMessagePreparator 是可以利用的。

    Please note that the mail code is a crosscutting(橫切的) concern(關注)  and is a perfect candidate(候選) for refactoring into a custom Spring AOP advice, which then could easily be applied to OrderManager target. Please see the AOP chapter.


    18.3.1. Pluggable MailSender implementations
    Spring comes with two MailSender implementations out of the box - the JavaMail implementation and the implementation on top of Jason Hunter's MailMessage class that's included in http://servlets.com/cos (com.oreilly.servlet). Please refer to JavaDocs for more information.

    18.4. Using the JavaMail MimeMessageHelper
    One of the components that comes in pretty handy when dealing with JavaMail messages is the org.springframework.mail.javamail.MimeMessageHelper. It prevents you from having to use the nasty APIs the the javax.mail.internet classes. A couple of possible scenarios:

    18.4.1. Creating a simple MimeMessage and sending it
    Using the MimeMessageHelper it's pretty easy to setup and send a MimeMessage:

    // of course you would setup the mail sender using
    // DI in any real-world cases
    JavaMailSenderImpl sender = new JavaMailSenderImpl();
    sender.setHost("mail.host.com");

    MimeMessage message = sender.createMimeMesage();
    MimeMessageHelper helper = new MimeMessageHelper(message);
    helper.setTo("test@host.com");
    helper.setText("Thank you for ordering!");

    sender.send(message);

    18.4.2. Sending attachments and inline resources
    Email allow for attachments, but also for inline resources in multipart messages. Inline resources could for example be images or stylesheet you want to use in your message, but don't want displayed as attachment. The following shows you how to use the MimeMessageHelper to send an email along with an inline image.

    JavaMailSenderImpl sender = new JavaMailSenderImpl();
    sender.setHost("mail.host.com");

    MimeMessage message = sender.createMimeMesage();

    // use the true flag to indicate you need a multipart message
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setTo("test@host.com");

    // use the true flag to indicate the text included is HTML
    helper.setText(
      "<html><body><img src='cid:identifier1234'></body></html>"
      true);

    // let's include the infamous windows Sample file (this time copied to c:/)
    FileSystemResource res = new FileSystemResource(new File("c:/Sample.jpg"));
    helper.addInline("identifier1234", res);

    // if you would need to include the file as an attachment, use
    // addAttachment() methods on the MimeMessageHelper

    sender.send(message);
       
    Inline resources are added to the mime message using the Content-ID specified as you've seen just now (identifier1234 in this case). The order in which you're adding the text and the resource are VERY important. First add the text and after that the resources. If you're doing it the other way around, it won't work!

     

    posted @ 2005-07-25 11:32 java世界暢談 閱讀(897) | 評論 (3)編輯 收藏

    Using the MethodInvokingJobDetailFactoryBean
    使用MethodInvokingJobDetailFactoryBean
    Often you just need to invoke a method on a specific object. Using the MethodInvokingJobDetailFactoryBean you can do exactly this:
    經常地,你僅僅需要調用一個對象的一個方法。使用MethodInvokingJobDetailFactoryBean,你可以正確地這樣做:

    <bean id="methodInvokingJobDetail"
      class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject"><ref bean="exampleBusinessObject"/></property>
        <property name="targetMethod"><value>doIt</value></property>
    </bean>


    The above example will result in the doIt being called on the exampleBusinessObject (see below):


    public class BusinessObject {
     
      // properties and collaborators
     
      public void doIt() {
        // do the actual work
      }
    }
       

    <bean id="exampleBusinessObject" class="examples.ExampleBusinessObject"/>
       
    Using the MethodInvokingJobDetailFactoryBean you don't need to create one-line jobs that just invoke a method, and you only need to create the actual business object and wire up the detail object.
    使用MethodInvokingJobDetailFactoryBean 你不需要創建一個在線的jobs,僅僅調用它的方法,你可以僅僅只需要創建一個實際的邏輯對象并且把它綁定到細節對象。

    By default, Quartz Jobs are stateless, resulting in the possibility of jobs interfering with each other. If you specify two triggers for the same JobDetail, it might be possible that before the first job has finished, the second one will start. If JobDetail objects implement the Stateful interface, this won't happen. The second job will not start before the first one has finished. To make jobs resulting from the MethodInvokingJobDetailFactoryBean non-concurrent, set the concurrent flag to false.

    缺省地,Quartz jobs是無狀態的,在jobs的可能性作為結果影響彼此。如果你限定兩個觸發器為同一個JohDetail,它在第一個job已經完成時是可能的,第二個將會開始。如果JobDetail實現了狀態接口,它將不會發生。
    <bean id="methodInvokingJobDetail"
      class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject"><ref bean="exampleBusinessObject"/></property>
        <property name="targetMethod"><value>doIt</value></property>
        <property name="concurrent"><value>false</value></property>
    </bean>
       
    Note: By default, jobs will run in a concurrent fashion.

     

    posted @ 2005-07-22 11:23 java世界暢談 閱讀(3139) | 評論 (0)編輯 收藏

     定時批處理作業是J2EE企業應用里很重要的一環,用來在晚間進行財務掛賬,數據轉存,新聞聯播等等操作。

        而在Spring里,已經很好的集成了Quartz,簡單到像配cron一樣,在xml文件里面配一下時間就可以自動執行,不需要寫一行代碼。Spring對Quartz大刀闊斧的簡化堪稱范例,Quartz項目組也許可以學習一下。

        <bean id="methodInvokingJobDetail"
            class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject"><ref bean="financeDAO"/></property>
            <property name="targetMethod"><value>confirmOrder</value></property>
        </bean>

        <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="methodInvokingJobDetail"/>
            </property>
            <property name="cronExpression">
                <value>0 0 6,12,20 * * ?</value>
            </property>
        </bean>
        <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list><ref local="cronTrigger"/></list>
            </property>
        </bean>

    上面這段配置文件規定了在早上6點和晚上8點執行financeDAO對象的confirmOrder()方法.


    附:cronExpression配置說明

    字段   允許值   允許的特殊字符
      0-59   , - * /
      0-59   , - * /
    小時   0-23   , - * /
    日期   1-31   , - * ? / L W C
    月份   1-12 或者 JAN-DEC   , - * /
    星期   1-7 或者 SUN-SAT   , - * ? / L C #
    年(可選)   留空, 1970-2099   , - * /

    posted @ 2005-07-20 21:37 java世界暢談 閱讀(15606) | 評論 (42)編輯 收藏

    TriggerListeners and JobListeners
    Listeners are objects that you create to perform actions based on events occuring within the scheduler. As you can probably guess, TriggerListeners receive events related to trigger,and JobListners receive events related to jobs.

    Trigger-related events include: trigger firings,trigger mis-firings(discussed in the "Triggers" sections of this document),and trigger completions (the jobs fired off by the trigger is finished).

    To create a listener,simply create an object the implements either the org.quartz.TriggerListener and/or org.quartz.JobListener interface. Listeners are then registered with the scheduler during run time ,and must be given a name(or rather ,they must advertise their own name via their getName()method.  Listeners can be registered as either "global" or "non-global". Global listeners receive events for ALL triggers/jobs, and non-global listeners receive events only for the specific triggers/jobs that explicitely name the listener in their getTriggerListenerNames() or getJobListenerNames() properties.

     scheduler.addGlobalJobListener(myJobListener);
    or
     scheudler.addJobListener(myJobListener);
     
    Listeners are not used by most users of Quartz,but are handy when application requirements create the need for the notification of events,without the Job itself explicitly nofifying the application.

    posted @ 2005-07-20 21:27 java世界暢談 閱讀(420) | 評論 (0)編輯 收藏

    More About CronTrigger
    更多關于CronTrigger

    CronTriggers are often more useful than SimpleTrigger, if you need a job-firing schedule that recurs based on calendar-like notions, rather than on the exactly specified intervals of SimpleTrigger.
    CronTriggers 比SimpleTrigger經常更加有用,如果你需要一個基于像日歷概念的重復 job-firing 調度,而不是在一個SimpleTrigger特定的間隔。

    With CronTrigger, you can specify firing-schedules such as "every Friday at noon", or "every weekday and 9:30 am", or even "every 5 minutes between 9:00 am and 10:00 am on every Monday, Wednesday and Friday".
    使用CronTrigger,你可以限定firing-schedulers例如 “每天中午“,或者”,”每天周日上午9:30“,或者甚至 “每5分鐘在上午9:00 到 10:00 每周一、周三、周五”

    Cron Expressions
    Cron 表達式

    Cron-Expressions are used to configure instances of CronTrigger. Cron-Expressions are strings that are actually made up of six sub-expressions, that describe individual details of the schedule. These sub-expression are separated with white-space, and represent:
    Cron 表達式被用來注冊CronTrigger實例的。Cron表達式是字符串,它由六個子表達式組成,它描述了不同的調度細節。這些子表達式被白色表達式隔開,表現:

    Seconds  秒
    Minutes  分
    Hours    時
    Day-of-Month  日
    Month         月
    Day-of-Week   周

    An example of a complete cron-expression is the string "0 0 12 ? * WED" - which means "every Wednesday at 12:00 pm".
    一個完整的Cron 表達式例子是字符串“0 0 12 ? * WEB” 意味著每周三上午12:00。

    Individual sub-expressions can contain ranges and/or lists. For example, the day of week field in the previous (which reads "WED") example could be replaces with "MON-FRI", "MON, WED, FRI", or even "MON-WED,SAT".
    單獨的子表達式可以包含平行的 和/或。例如,在上一個例子一周的一天字段(它讀作"WED")可以被“MON-FRI”,"MON,WED,FRI",或者甚至"MON-WED,SAT"替換掉。

    Wild-cards (the '*' character) can be used to say "every" possible value of this field. Therefore the '*' character in the "Month" field of the previous example simply means "every month". A '*' in the Day-Of-Week field would obviously mean "every day of the week".
    統配符("*"字符)可以被用來作為這個字段的"每一個"可能值。所以,在上一個例子月字段中的"*"字符表示每個月。 一個"*"在周天將明顯意味著周的每一天。

    All of the fields have a set of valid values that can be specified. These values should be fairly obvious - such as the numbers 0 to 59 for seconds and minutes, and the values 0 to 23 for hours. Day-of-Month can be any value 0-31, but you need to be careful about how many days are in a given month! Months can be specified as values between 0 and 11, or by using the strings JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC. Days-of-Week can be specified as vaules between 1 and 7 (1 = Sunday) or by using the strings SUN, MON, TUE, WED, THU, FRI and SAT.
    所有字段都用一個合法限定的值。這些值應該是明顯的,例如0到59數字為秒和分的限定,0到23為小時。月的某天可以是0-31的,或者你需要消息給個月有多少天!月份可以被限定在0到11,或者,使用英文字符串縮寫。一個禮拜的一天可以被限定作為1到7(1=Sunnday)或者使用英文字符串。


    The '/' character can be used to specify increments to values. For example, if you put '0/15' in the Minutes field, it means 'every 15 minutes, starting at minute zero'. If you used '3/20' in the Minutes field, it would mean 'every 20 minutes during the hour, starting at minute three' - or in other words it is the same as specifying '3,23,43' in the Minutes field.
    "/"字符可以內用來限定值的增加。例如,如果你將'0/15'放到分鐘字段,它意味著"每15分鐘,開始于0分鐘"。如果你使用"3/20"在分鐘字段中,你將意味著"一個小時內每20分鐘,開始于3分鐘"---  或者換言之,它和在分鐘字段"3,23,43"限定是一樣的。


    The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify "no specific value". This is useful when you need to specify something in one of the two fields, but not the other. See the examples below (and CronTrigger JavaDOC) for clarification.

    "?"字符是允許為月的某一天或者周的某一天字段的。它被用來限定"沒有限定值"。這是有用的,當你需要限定一些事情在一個或兩個字段中,但不是這里的。

    The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" or "FRIL" both mean "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.

    "L"字符是允許用來月某天和周某天字段。這個字符是一個"last"的縮寫,但是它有不同的意義在兩個字段的其中之一。例如,這個值"L"在月字段的某一天意味著" 這個月的最后一天",31或者28等等。

    Here are a few more examples of expressions and their meanings - you can find even more in the JavaDOC for CronTrigger

    CronTrigger Example 1 - an expression to create a trigger that simply fires every 5 minutes

      "0 0/5 * * * ?"

    CronTrigger Example 2 - an expression to create a trigger that fires every 5 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:05:10 am, etc.).

      "10 0/5 * * * ?"

    CronTrigger Example 3 - an expression to create a trigger that fires at 10:30, 11:30, 12:30, and 13:30, on every Wednesday and Friday.

      "0 30 10-13 ? * WED,FRI"

    CronTrigger Example 4 - an expression to create a trigger that fires every half hour between the hours of 8 am and 10 am on the 5th and 20th of every month. Note that the trigger will NOT fire at 10:00 am, just at 8:00, 8:30, 9:00 and 9:30

      "0 0/30 8-9 5,20 * ?"

    Note that some scheduling requirements are too complicated to express with a single trigger - such as "every 5 minutes between 9:00 am and 10:00 am, and every 20 minutes between 1:00 pm and 10:00 pm". The solution in this scenario is to simply create two triggers, and register both of them to run the same job.

    posted @ 2005-07-20 15:25 java世界暢談 閱讀(1339) | 評論 (0)編輯 收藏

    僅列出標題
    共29頁: First 上一頁 21 22 23 24 25 26 27 28 29 下一頁 
    主站蜘蛛池模板: 亚洲情侣偷拍精品| 免费看国产一级片| 亚洲色图.com| 最近2022中文字幕免费视频| 亚洲AV无码久久| 日本免费大黄在线观看| 久久精品国产亚洲香蕉| 亚洲视频免费播放| 中文字幕亚洲综合小综合在线 | 久草免费福利在线| 最新仑乱免费视频| 亚洲AV无码一区二区一二区| 永久黄网站色视频免费直播 | 久久精品国产亚洲AV嫖农村妇女| 亚洲天堂男人天堂| 91精品免费高清在线| 亚洲人成免费网站| 国产最新凸凹视频免费| 无人视频免费观看免费视频 | 99久久免费国产精精品| 亚洲熟妇无码另类久久久| 成人精品视频99在线观看免费| 成人免费一级毛片在线播放视频 | 亚洲综合久久一本伊伊区| 女人张开腿等男人桶免费视频| 在线观看午夜亚洲一区| 好吊色永久免费视频大全| 亚洲AV无码国产丝袜在线观看| 麻豆一区二区三区蜜桃免费| 天堂亚洲免费视频| 国产精品偷伦视频观看免费| 亚洲人成影院77777| 国产一精品一aⅴ一免费| 大地影院MV在线观看视频免费| 国产精品免费_区二区三区观看 | 亚洲一区二区免费视频| 精品日韩99亚洲的在线发布| 国产一级做a爱免费视频| 久久成人免费播放网站| 亚洲精品无码中文久久字幕| 久久综合亚洲色HEZYO国产|