期待更好更穩定的開源FrameWork的出現,讓我們一起努力吧!  
          日歷
          <2007年9月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456
          統計
          • 隨筆 - 78
          • 文章 - 1
          • 評論 - 29
          • 引用 - 0

          導航

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案(42)

          文章檔案(37)

          相冊

          搜索

          •  

          積分與排名

          • 積分 - 45228
          • 排名 - 1064

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

           

          最近忙于項目,一直沒有更新blog,請大家見諒。
          在項目中使用了Lucene全文檢索,考慮到系統的特性,把Lucene的全文檢索索引創建時間放在夜晚,已減輕系統的壓力。
          首先,需要寫一個類,這個類是用來執行具體的操作。也就是你想做什么事情,這個類需要extends org.springframework.scheduling.quartz.QuartzJobBean 類。
          比如:

           

            1package com.finegold.digimus.service.config;
            2
            3import java.util.Date;
            4import java.util.List;
            5
            6import org.apache.log4j.Logger;
            7import org.quartz.JobExecutionContext;
            8import org.quartz.JobExecutionException;
            9import org.springframework.scheduling.quartz.QuartzJobBean;
           10
           11import com.finegold.digimus.comm.StringHelper;
           12
           13import com.finegold.digimus.lucene.index.service.imp.AddCatalogArticleDataDocument;
           14import com.finegold.digimus.lucene.index.service.imp.AddMediaContentDocument;
           15import com.finegold.digimus.lucene.index.service.imp.IndexFactory;
           16import com.finegold.digimus.service.CatalogArticleDataService;
           17import com.finegold.digimus.service.MediaContentService;
           18import com.finegold.digimus.service.bean.IndexPath;
           19
           20/**
           21 * @author 汪心利 2007-9-6 下午03:41:29
           22 * @copyRigth FineGold 2007
           23 * @Describle 定時創建Lucene索引任務的定時器
           24 */

           25
           26public class IndexQuartz extends QuartzJobBean {
           27
           28 private Logger logger = Logger.getLogger(IndexQuartz.class);
           29
           30 private MediaContentService mediaContent;
           31
           32 private CatalogArticleDataService catalogArticleData;
           33
           34 private IndexPath indexPath;
           35
           36 /**
           37  * @return the indexPath
           38  */

           39 public IndexPath getIndexPath() {
           40  return indexPath;
           41 }

           42
           43 /**
           44  * @param indexPath
           45  *            the indexPath to set
           46  */

           47 public void setIndexPath(IndexPath indexPath) {
           48  this.indexPath = indexPath;
           49 }

           50
           51 /**
           52  * @return the catalogArticleData
           53  */

           54 public CatalogArticleDataService getCatalogArticleData() {
           55  return catalogArticleData;
           56 }

           57
           58 /**
           59  * @param catalogArticleData
           60  *            the catalogArticleData to set
           61  */

           62 public void setCatalogArticleData(
           63   CatalogArticleDataService catalogArticleData) {
           64  this.catalogArticleData = catalogArticleData;
           65 }

           66
           67 /**
           68  * @return the mediaContent
           69  */

           70 public MediaContentService getMediaContent() {
           71  return mediaContent;
           72 }

           73
           74 /**
           75  * @param mediaContent
           76  *            the mediaContent to set
           77  */

           78 public void setMediaContent(MediaContentService mediaContent) {
           79  this.mediaContent = mediaContent;
           80 }

           81
           82 @Override
           83 protected void executeInternal(JobExecutionContext arg0)
           84   throws JobExecutionException {
           85
           86//在這里加入你的操作
           87  StringBuffer logInfo = new StringBuffer();
           88  logInfo.append("").append(StringHelper.encodeHTML(new Date())).append(
           89    "開始執行創建索引的任務調度");
           90  logger.info(logInfo.toString());
           91  try {
           92   List m_list = mediaContent.findByMediaid(nullnull);
           93   IndexFactory.getInstance().createIndex(m_list,
           94     new AddMediaContentDocument(),
           95     indexPath.getMediaIndexPath());
           96   List c_list = catalogArticleData.loadAllData();
           97   IndexFactory.getInstance().createIndex(c_list,
           98     new AddCatalogArticleDataDocument(),
           99     indexPath.getCatalogIndexPath());
          100   logger.info(StringHelper.encodeHTML(new Date()) + "創建索引任務完成!");
          101
          102  }
           catch (Exception e) {
          103   logger.error("使用Spring定時器創建索引出錯!");
          104  }

          105 }

          106}

          107
          108


          然后在applicationContext.xml中配置:

           

          <!-- =========================Quartz TimeTask  配置 ========================= -->

           
          <bean id="indexJob"
            class
          ="org.springframework.scheduling.quartz.JobDetailBean">
            
          <property name="jobClass">
             
          <value>
              com.finegold.digimus.service.config.IndexQuartz
          <!-- 剛剛寫的類-->
             
          </value>
            
          </property>
            
          <property name="jobDataAsMap">
             
          <map><!-- 類里一些屬性 key:propertyName-->
              
          <entry key="indexPath">
               
          <ref local="indexPath" />
              
          </entry>
              
          <entry key="catalogArticleData">
               
          <ref bean="catalogArticleDataService" />
              
          </entry>
              
          <entry key="mediaContent">
               
          <ref bean="mediaContentService" />
              
          </entry>
             
          </map>
            
          </property>
           
          </bean>

          <!-- 配置那個任務在何時執行 -->

           
          <bean id="cronTrigger"
            class
          ="org.springframework.scheduling.quartz.CronTriggerBean">
            
          <property name="jobDetail">
             
          <ref bean="indexJob" />
            
          </property>
            
          <property name="cronExpression">
             
          <value>0 9 * * * ?</value>
             
          <!--<value>* * 23 * * ?</value>-->
            
          </property>
           
          </bean>

          <!-- 將任務放入 SchedulerFactoryBean--> 
          <bean id="scheduler"
            class
          ="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            
          <property name="triggers">
             
          <list>
              
          <ref bean="cronTrigger" />
             
          </list>
            
          </property>
           
          </bean>

          這只是其中的一種方式,還有其它的方式。請等待......



          posted on 2007-09-07 11:42 BlueSky_itwangxinli 閱讀(517) 評論(0)  編輯  收藏

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


          網站導航:
           
           
          Copyright © BlueSky_itwangxinli Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 永吉县| 商洛市| 积石山| 肇东市| 城口县| 巴东县| 沛县| 德州市| 海宁市| 建平县| 堆龙德庆县| 射洪县| 福鼎市| 含山县| 浪卡子县| 武平县| 丘北县| 元氏县| 阳谷县| 石楼县| 宜章县| 图片| 胶南市| 乃东县| 轮台县| 宣武区| 昆山市| 宿州市| 东台市| 阳江市| 岳阳县| 日照市| 丰都县| 双桥区| 洪湖市| 盱眙县| 苗栗市| 安仁县| 涿州市| 枣阳市| 朝阳县|