ROME更新RSS类 有什么可以再优化的地方 发现更新还是有点慢的

package org.zjut.romefunction;

/**
 * this class is update the news;
 * @author xuhaimin
 * 
 */

import java.util.Date;
import java.util.Iterator;
import org.zjut.DAOFactory.DAOFactory;
import org.zjut.PO.Feed;
import org.zjut.PO.Item;
import org.zjut.PO.Rss;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;

public class UpdateItems {

	public void perform(Rss rss) {
		System.out.println(rss.getId());

		SyndFeed syndfeed = new ParseRss().getSyndFeed(rss);

		String title = syndfeed.getTitle();
		Feed feed = DAOFactory.getIntance().createFeedDAO().getFeedByTitle(
				title);
		Date maxdate = getMaxDate(title);
		Iterator intor = syndfeed.getEntries().iterator();
		while (intor.hasNext()) {
			SyndEntry synden = (SyndEntry) intor.next();
			Date date = synden.getPublishedDate();
			if (date == null)
				continue;
			if (date.after(maxdate)) {
				System.err.println("当前数据库中" + feed.getTitle() + " 最新时间是"
						+ maxdate);
				System.err.println("当前rss 最新时间是" + date);

				/**
				 * 如果是更新新闻 就入库
				 */
				Item item = new Item();
				item.setTitle(synden.getTitle());
				String description=synden.getDescription().getValue().replaceAll("<[.[^<]]*>","");
				if(description==null||description.equals(""))
					item.setDescription("对不起,没有该新闻的描述");
				item.setDescription(description);
				item.setAuthor(synden.getAuthor());
				item.setSource("");
				item.setPubDate(synden.getPublishedDate());
				item.setLink(synden.getLink());
				item.setFeed(feed);

				System.err.println("@ 服务器正在更新" + feed.getTitle()
						+ "的内容..........................................");
				DAOFactory.getIntance().createItemDAO().saveItem(item);
			} else {
				break;
			}
		}
	}

	public Date getMaxDate(String title) {
		Feed feed = DAOFactory.getIntance().createFeedDAO().getFeedByTitle(
				title);
		Long feedid = feed.getId();
		Date date = org.zjut.HibernateUtil.Util.maxDate(feedid);
		return date;
	}

}

你可能感兴趣的:(Google,sun)