JCS是一个用java语言实现的缓存系统,它是apache项目中的一员,它提供动态数据数据的管理,适用于高读低写的应用环境。它提供了很多的特性,所以它已经不是仅是在内存中放置对象那么简单的事情了。它提供的特性可以在它的官方网站上看到。 使用起来也很简单,它的配置和log4j有些相似之处,下面贴出一个测试用的配置文件: jcs.default= jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes jcs.default.cacheattributes.MaxObjects=10000 jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache jcs.default.cacheattributes.cacheattributes.UseMemoryShrinker=true jcs.... more
Tag Archives: java
等待多线程执行结束的例子
下面代码取自jdk的javadoc public static void main(String[] argv) throws InterruptedException { int N = 20; CountDownLatch startSignal = new CountDownLatch(1); CountDownLatch doneSignal = new CountDownLatch(N); for (int i = 0; i < N; ++i) { // create and start threads new Thread(new Worker(startSignal, doneSignal)).start(); } System.out.println("00001"); // don't let run yet startSignal.countDown(); // let all threads proceed System.out.println("00002"); doneSignal.await(); // wait for all to finish System.out.println("all ... more
spring与struts2的集成
1:web.xml文件的配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>guoguo2</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring.xml</param-value> </context-param> <listener> ... more
hibernate的subclass的配置
下面代码仅做为示例使用 方法一:分文件配置hibernate文件 1、基类 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping auto-import="false" default-lazy="false"> <class name="com.guoguo.impl.clazz" table="gg_clazz" lazy="false"> <meta attribute="class-description"> subclass;com.guoguo.impl.clazz01 subclass;com.guoguo.impl.clazz02 </meta> <cache usage="read-write" /> <id name="id" column="id"> <ge... more
以前开发中遇到的部分报错
1:2010-5-26 16:54:42 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener java.lang.IllegalStateException: Web app root system property already set to different value: ‘webapp.root’ = [/home/eclweb/./] instead of [/home/eco/./] – Choose unique values for the ‘webAppRootKey’ context-param in your web.xml files! at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:132) at org.springframew... more
ThreadPoolTaskExecutor线程池简单封装
创建spring线程池,使用它时只需要调用execute方法,封装的目的是在其中启动一个线程,用它来做打印线程池中线程状态的工作,所以只能说是简单的封装。 /** * learnguoguo * GuoThreadPoolTaskExecutor.java * 2009-7-5 上午04:03:36 * @author guoguo, All right reserved. */ package com.guoguo.site.thread; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.ThreadPoolExecutor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; /** * @author guoguo GuoThreadPoo... more
solr搜索组件的配置
web.xml的配置: <!-- solr core的配置,也可使用jndi配置 --> <env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>/opt/solr/multicore</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry> ... <!-- 管理页面就会为/solr/admin/* --> <filter> <filter-name>SolrRequestFilter</filter-name> <filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class> <init-param> <param-name>path-prefix</param-name> <param-value>/solr</param-value> </init-param> <!-- If you are wiring ... more
freemark处理文本模板的方法
Java的Freemark处理文本模板的方法,此应该可用于发送邮件程序。 /** * project: guoguo * CryptoUtil.java 2011-2-18 上午10:02:39 * guoguo, tianjiaguo#tianjiaguo.com All right reserved. */ .... private static final Configuration configuration = new Configuration(); static { configuration.setEncoding(Locale.getDefault(), "UTF-8"); } /** * 2011-3-11 下午06:08:04 guoguo * @param data * @param templateStr * @return */ public static String processStringTemplate(Map<String, Object> data, String templateStr) { StringReader reader = new StringReader(templateStr); try { Template tem... more
cookie信息在ie设置过期时间的方法
下面这个代码,在opera,firefox,Google浏览器中跑的正常,但在ie浏览器(至少ie6是这样),设置的MaxAge不好用,当设置保留Cookie时,不好使,IE6在对话结束后会删除这些个Cookie,为什么说不好用呢,因为设置MaxAge为大于0的数设置不上,为0(删除Cookie)或-1(过期时间为当前对话结束)时极为好用。 Cookie cookie_sid = new Cookie(GuoGuoWebConstant.COOKIE_SECURITY_ID, sid ); cookie_sid.setPath("/"); cookie_sid.setMaxAge(24 * 30 * 24 * 60 * 60); cookie_hsid.setVersion(1); response.addCookie(cookie_hsid); 经俄多方测试终于发现问题的所在,上面的代码只要注释掉cookie_hsid.setVersion(1);这句话就好用了。shit。原因好像... more
java-AES加密解密
关于加密解密可以把密钥保存到文件中,然后在加密解密时取出来使用,以节省生成密钥用的时间,此处的两个方法不是这样做的,每次都是重新生成它。 /** * @update 修正在一些系统上加密字串解密时报错无法解密的问题 2011.02.19 by guoguo * @update Max系统以\r换行,修正max上的问题 2011.03.08 by guoguo * @update jdk1.6警告方法过期问题 2011.03.29 by guoguo */ 在一些系统上,使用 new SecureRandom(key.getBytes())得到的SecureRandom会产生问题。SecureRandom实现会依赖于操作系统內部的状态,除非调用完getInstance后又调用了setSeed方法;该实现在 windows 上每次生成的 key 都相同,但是在一些系统如solaris、部分 linux 系... more
更改指定目录下所有的java文件的编码为UTF-8
修改指定目录下的所有java文件的编码,由GBK修改为UTF-8 @update 读文件时使用自定义的编码格式GBK /** * @author guoguo Email:tianjiaguo@tianjiaguo.com 2010-8-25上午09:15:32 * */ public class FileChange { public static void main(String[] args) { getListFiles("D:/java/com/tianjiaguo"); } public static void getListFiles(String path) { File file = new File(path); FileChange.listFile(file); } public static void listFile(File f) { if (f.isDirectory()) { if (f.getName().startsWith(".")) { return; } File[] t = f.listFiles(); for (int i = 0; i < t.length; i++) { ... more
NoClassDefFoundError: antlr/ANTLRException报错问题的修改
使用subclass配置hibernate的时候,使用父类的service操作数据库时会报如下的错误,其原因是缺少一个jar包,引入antlr-2.7.6rc1.jar就没有问题了。 java.lang.NoClassDefFoundError: antlr/ANTLRException at org.hibernate.hql.ast. ASTQueryTranslatorFactory .createQueryTranslator( ASTQueryTranslatorFactory.java:35) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:72) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71) at org.hibernate.impl.AbstractSessionImpl.getHQLQuery... more
jsp页面变态的问题
用这种方式引入jsp文件,可以使用父页面的属性,如request属性 <jsp:directive.include file="/commons/related-products.html" /> taglib有的时候不识别,这时可用jsp-config包括着它,下面代码同样设置了html文件为jsp文件,这样可避免html文件中汉字的乱码。 <jsp-config> <jsp-property-group> <url-pattern>*.html</url-pattern> <el-ignored>true</el-ignored> <page-encoding>UTF-8</page-encoding> </jsp-property-group> <taglib> <taglib-uri>http://www.tianjiaguo.com/tags</taglib-uri> <taglib-location>/WEB-INF/tld/guoguo.tld</taglib-location> </taglib... more