展开全部
Java中可以使用队列来保存62616964757a686964616fe59b9ee7ad9431333337613163数据,当使用的时候,加上锁,防止其他进程访问,当不用的时候保存到数据库里面,示例如下:package com.henry;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class CacheDataTest {
static Map dataMap=new HashMap();
static ReadWriteLock lock=new ReentrantReadWriteLock();//创建读写锁的实例
static Object getData(Integer key){
lock.readLock().lock();//读取前先上锁
Object val=null;
try{
val=dataMap.get(key);
if(val == null){
// Must release read lock before acquiring write lock
lock.readLock().unlock();
lock.writeLock().lock();
try{
//