100求实现数据缓存的代码:

birditren2001 2003-10-20 02:47:55
比如说我用socket收到一条信息,先放到缓存中,然后处理数据的程序从缓存中读取数据,经过处理,然后插入到数据库中,请问该如何实现这种缓存机制?好像要用到链表或者队列什么的。
...全文
56 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
birditren2001 2003-10-21
  • 打赏
  • 举报
回复
不知道我的问题用JMS是否可以解决?
listlike 2003-10-21
  • 打赏
  • 举报
回复
去这里看看
http://jakarta.apache.org/commons/pool/
birditren2001 2003-10-21
  • 打赏
  • 举报
回复
楼上是指free的中间件吗?各位高手帮忙。
etre 2003-10-21
  • 打赏
  • 举报
回复
java的缓存机制我看到网上有free的,做的很好的。我不知道在那里了,你去看看吧
birditren2001 2003-10-21
  • 打赏
  • 举报
回复
楼上的大哥:
你的代码还没来得及研究,我只是在JB中新建一个项目,然后新建class,copy了你的代码,
然后把首行package修改成我自己的package,但是程序throws CacheException的地方都标记为红色错误标记,怎么回事?错误信息:"Cache.java": cannot resolve symbol: class CacheException in interface smscache.Cache at line 16, column 38 还有,CachedItem.java中,freshTimestamp = Timestamper.next();和unlockTimestamp = Timestamper.next();这两行都有红色错误标记,错误信息是:"CachedItem.java": cannot resolve symbol: variable Timestamper in class smscache.CachedItem at line 22, column 18
水电费123343 2003-10-21
  • 打赏
  • 举报
回复
//$Id: CacheConcurrencyStrategy.java,v 1.4 2003/05/20 12:56:08 oneovthafew Exp $
package net.sf.hibernate.cache;

/**
* Implementors manage transactional access to cached data. Transactions
* pass in a timestamp indicating transaction start time.
*/
public interface CacheConcurrencyStrategy {

/**
* Attempt to retrieve an object from the cache
* @param key
* @param txTimestamp a timestamp prior to the transaction start time
* @return the cached object or <tt>null</tt>
* @throws CacheException
*/
public Object get(Object key, long txTimestamp) throws CacheException;
/**
* Attempt to cache an object
* @param key
* @param value
* @param txTimestamp a timestamp prior to the transaction start time
* @return <tt>true</tt> if the object was successfully cached
* @throws CacheException
*/
public boolean put(Object key, Object value, long txTimestamp) throws CacheException;
/**
* We are going to attempt to update/delete the keyed object
* @param key
* @throws CacheException
*/
public void lock(Object key) throws CacheException;
/**
* We have finished the attempted update/delete (which may or may
* not have been successful).
* @param key
* @throws CacheException
*/
public void release(Object key) throws CacheException;
public void remove(Object key) throws CacheException;
public void clear() throws CacheException;
public void destroy();
}






水电费123343 2003-10-21
  • 打赏
  • 举报
回复
//$Id: CachedItem.java,v 1.3 2003/01/05 02:11:20 oneovthafew Exp $
package net.sf.hibernate.cache;

import java.io.Serializable;

/**
* An item of cached data, timestamped with the time it was cached,
* when it was locked, when it was unlocked.
* @see ReadWriteCache
*/
public final class CachedItem implements Serializable {

private long freshTimestamp;
private boolean fresh;
private long unlockTimestamp;
private int lock;
private Object value;

public CachedItem(Object value) {
this.value = value;
freshTimestamp = Timestamper.next();
fresh = true;
unlockTimestamp = -1;
}

public long getFreshTimestamp() {
return freshTimestamp;
}

public long getUnlockTimestamp() {
return unlockTimestamp;
}

public Object getValue() {
return value;
}

public boolean isFresh() {
return fresh;
}

public void lock() {
if ( 0 == lock++ ) {
fresh = false;
value = null;
}
}
public void unlock() {
if ( --lock == 0 ) {
unlockTimestamp = Timestamper.next();
}
}
public boolean isUnlocked() {
return lock==0;
}

}






水电费123343 2003-10-21
  • 打赏
  • 举报
回复
//$Id: Cache.java,v 1.5 2003/05/20 12:56:07 oneovthafew Exp $
package net.sf.hibernate.cache;

/**
* Implementors define a caching algorithm. All implementors
* <b>must</b> be threadsafe.
*/
public interface Cache {
/**
* Get an item from the cache
* @param key
* @return the cached object or <tt>null</tt>
* @throws CacheException
*/
public Object get(Object key) throws CacheException;
/**
* Add an item to the cache
* @param key
* @param value
* @throws CacheException
*/
public void put(Object key, Object value) throws CacheException;
/**
* Remove an item from the cache
*/
public void remove(Object key) throws CacheException;
/**
* Clear the cache
*/
public void clear() throws CacheException;
/**
* Clean up
*/
public void destroy() throws CacheException;
/**
* Set the cache region name
* @param regionName
* @throws CacheException
*/
public void setRegion(String regionName) throws CacheException;
}






birditren2001 2003-10-21
  • 打赏
  • 举报
回复
继续顶
birditren2001 2003-10-20
  • 打赏
  • 举报
回复
顶一下。
    本课程全程使用目前比较流行的开发工具idea进行开发,涉及到目前互联网项目中最常用的高并发解决方案技术, 如dubbo,redis,solr,freemarker,activeMQ,springBoot框架,微信支付,nginx负载均衡,电商活动秒杀,springSecurity安全框架,FastDFS分布式文件服务器,还会涉及到代码生成器,   前台的技术有angularJS和BootStrap框架,此课程内容丰富实战性强,如果你还是传统项目的开发人员,那你学完本课程会有很大的收获,让你的薪资上涨,5K以上,让你完全感受到了互联网思维带来的高 并发解决方案的思路,如果你是开发的小白,建议你学完Spring,SpringMVC,MyBatis框架后再来学习本门课程,学完以后会让你完全体验到企业级开发的流程.在职开发人员学完后会让你的薪资更高,让你更了解互联网是如何解决高并发 学完SSM框架的同学就可以学习,能让你切身感受到企业级开发环境目标1:完成solr环境安装、中文分析器和业务域的配置目标2:会使用Spring Data Solr完成增删改查操作目标3:完成批量数据导入功能目标4:完成按关键字搜索功能目标5:实现考拉易购搜索结果高亮显示功能目标6:说出考拉易购搜索的业务规则和实现思路目标7:完成查询分类列表的功能目标8:完成缓存品牌和规格数据的功能目标9:完成显示品牌和规格数据的功能目标10:完成过滤条件构建的功能目标11:完成过滤查询的功能目标11:实现考拉易购价格区间筛选功能目标12:实现搜索结果分页功能目标13:理解多关键字搜索目标14:实现搜索结果排序功能目标15:实现隐藏品牌列表功能目标16:实现搜索页与首页对接功能目标17:完成更新索引库的功能

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧