开发工具:
文件大小: 4kb
下载次数: 0
上传时间: 2009-04-20
详细说明: package teacherclub.util; import java.io.File; import java.io.InputStream; import java.util.Date; import java.util.Properties; import com.danga.MemCached.MemCachedClient; import com.danga.MemCached.SockIOPool; /** * @author Chergen * */ public class MCCUtil { /** * @param args */ protected static MemCachedClient mcc = new MemCachedClient(); /**�Ƿ���� MCC*/ private static boolean IS_DISABLED = false; /**Ĭ��ʧЧʱ��*/ private static long DEF_EXPIRE = 10000; /**���� �Ƿ���� MCC
true:���ã�false:����*/ public static void setDisable(boolean isDisable){ IS_DISABLED = isDisable; if(!IS_DISABLED) init(); } /**���� Ĭ��ʧЧʱ��*/ public static void setDefExpire(long expire){ DEF_EXPIRE = expire; } static { init(); } private static void init(){ Properties props = new Properties(); try{ String path = WebUtil.getWebinfPath()+File.separatorChar+"properties"+File.separatorChar+"mcc.properties"; File file = new File(path); InputStream is = new java.io.FileInputStream(file); props.load(is); is.close(); System.out.println("Successfully initialize MCC!"); }catch(Exception e){ IS_DISABLED = true; System.out.println("Failed to initialize MCC!\nPleanse check out the mcc.properties."); e.printStackTrace(); return ; } String[] servers = props.getProperty("mcc.servers", "localhost:11211").split(",");//{ "mcc.host:11211" }; String[] weightsStr = props.getProperty("mcc.weights", "3").split(","); Integer[] weights = new Integer[weightsStr.length];//{ 3 }; for (int i = 0; i < weightsStr.length; i++) { try{ weights[i] = Integer.parseInt(weightsStr[i]); }catch(Exception e){weights[i] = 3;} } // ����һ��ʵ�����SockIOPool SockIOPool pool = SockIOPool.getInstance(); // set the servers and the weights // ����Memcached Server pool.setServers(servers); pool.setWeights(weights); // set some basic pool settings // 5 initial, 5 min, and 250 max conns // and set the max idle time for a conn // to 6 hours pool.setInitConn(5); pool.setMinConn(5); pool.setMaxConn(250); pool.setMaxIdle(1000 * 60 * 60 * 12); // set the sleep for the maint thread // it will wake up every x seconds and // maintain the pool size pool.setMaintSleep(30); // Tcp�Ĺ�������ڷ���һ���֮ǰ�����ػ����ȴ�Զ����� // ����һ�η��͵İ��ȷ����Ϣ��4�������Ϳ��Թر����ֵĻ��棬 // �������������˾ͷ��� pool.setNagle(false); // l�ӽ�b��Գ�ʱ�Ŀ��� pool.setSocketTO(3000); // l�ӽ�bʱ�Գ�ʱ�Ŀ��� pool.setSocketConnectTO(0); // initialize the connection pool // ��ʼ��һЩֵ����MemcachedServer�ν�bl�� pool.initialize(); // lets set some compression on for the client // compress anything larger than 64k mcc.setCompressEnable(true); mcc.setCompressThreshold(64 * 1024); } /**�������*/ public static void inputData(String key, Object Data){ inputData(key, Data, DEF_EXPIRE); } /**�������*/ public static void inputData(String key, Object Data, long expire){ if(!IS_DISABLED) mcc.set(key, Data, new Date(expire)); } /**ȡ�����*/ public static Object outputData(String key){ if(IS_DISABLED) return null; return mcc.get(key); } private static void bulidCache() { // set(key,value,Date) ,Date��һ�����ʱ�䣬�������������ʱ����Ч�Ļ������ﴫ�ݵ�new Date(long // date) �в���date����Ҫ�Ǹ���ڻ����1000��ֵ�� // ��Ϊjava client��ʵ��Դ����������ʵ�ֵ� expiry.getTime() / 1000 ��Ҳ����˵����� // С��1000��ֵ������1000�Ժ���0�����2����� mcc.set("test", "This is a test String", new Date(10000)); // ʮ������ } private static void output() { // ��cache��ȡֵ String value = (String) mcc.get("test"); System.out.println(value); } public static void main(String[] args) { bulidCache(); output(); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.