期待更好更稳定的开源FrameWork的出现,让我们一起努力吧!  
日历
<2007年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
统计
  • 随笔 - 78
  • 文章 - 1
  • 评论 - 29
  • 引用 - 0

导航

常用链接

留言簿(1)

随笔分类

随笔档案(42)

文章档案(37)

相册

搜索

  •  

积分与排名

  • 积分 - 44321
  • 排名 - 1068

最新随笔

最新评论

阅读排行榜

评论排行榜

 

最近忙于项目,一直没有更新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 阅读(500) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © BlueSky_itwangxinli Powered by: 博客园 模板提供:沪江博客