2016年8月31日星期三

@Transactional(readOnly=true) 和 @Cache谁优先?

执行下来,目前看到的是@Transaction肯定执行,它比@Cache先跑。

而不是说,先去@Cache里面找,找不到再开始 @Transaction,也就是计算你定义了@Cache,加了@Transaction的地方,仍然会先去拿一个connection,再还回Pool。

实际场景中,@Cache了Service层返回的内容,然后Controller层疯狂call Service,量大时仍然有挤爆max connection的可能。

https://github.com/arey/java-object-mapper-benchmark

https://github.com/arey/java-object-mapper-benchmark
http://mariusz.wyszomierski.pl/en/mapping-dozer-vs-mapstruct/
http://vytas.io/blog/java/java-object-to-object-mapping-which-framework-to-choose-part-2/
http://stackoverflow.com/questions/34786737/java-mapping-selma-vs-mapstruct/35327974

http://java-performance.com/

http://java-performance.com/

2016年8月30日星期二

deepclone

    // http://howtodoinjava.com/core-java/cloning/a-guide-to-object-cloning-in-java/
    // http://stackoverflow.com/questions/2156120/java-recommended-solution-for-deep-cloning-copying-an-instance

测试了几个,不是


        // method 1, ok
        // List<T> dst = (List<T>)SerializationUtils.clone(ArrayList.class.cast(src)); //too slow

        /*
        //method 2, ng      
        List<T> dst = new ArrayList<T>();
        CollectionUtils.addAll(dst,  new Object[src.size()]);
        Collections.copy(dst, src);
        */

        /*
        //method 3, ng
        T[] srcT = toArray(src);
        T[] dstT = (T[])Array.newInstance(srcT.getClass().getComponentType(), src.size());
        System.arraycopy(srcT, 0, dstT, 0, srcT.length);
        List<T> dst = Arrays.asList(dstT);      
        */

        /*
        //method 4, ng, need Clonable
        List<T> dst = new ArrayList<T>();
        for (T o: src)
        {
            T cloned = null;
            if (o instanceof Cloneable)
            {
                //cloned = o.clone();
                try
                {
                    cloned = (T)(o.getClass().getMethod("clone").invoke(o));
                } catch (Exception e)
                {
                    e.printStackTrace();
                }              
            }
            else {                              
                cloned = SerializationUtils.clone(o);
            }          
            dst.add(cloned);
        }
        */

        // method 5, ok
        List<T> dst = (List<T>) cloner.deepClone(src);

2016年8月28日星期日

使用mybatis的resultmap,将native 的ResultSet变成VO

混用mybatis和native jdbc时,一直考虑能否直接使用定义在mybatis里面定义的resultmap,发愁
了很久。

今天终于找到了方法,旧的版本是不支持的,用了新的3.4.1。

代码如下
    @SuppressWarnings("unchecked")
    public static <T> List<T> getListFromResultSet(ResultSet rs, String resultMapId) throws SQLException
    {
        List<Object> l;
        Configuration cfg = getSqlSession().getConfiguration();       
        ResultMap resultMap = cfg.getResultMap(resultMapId);       
        MappedStatement ms = cfg.getMappedStatements().iterator().next();//get first MappedStatement       
        DefaultResultSetHandler drsh = new DefaultResultSetHandler(null, ms, null, null, null, null);           
        ResultSetWrapper rsw = new ResultSetWrapper(rs, cfg);;
        DefaultResultHandler resultHandler = new DefaultResultHandler(cfg.getObjectFactory()) {
            @Override
            public void handleResult(ResultContext<? extends Object> context)
            {
                super.handleResult(context);
                //log.debug("{}", context.getResultObject());               
            }
        };
        drsh.handleRowValues(rsw, resultMap, resultHandler, new RowBounds(), null);
        l = (List<Object>)resultHandler.getResultList();
        for (Object o: l)
        {
            log.debug("{}", o);
        }
       
        return (List<T>)(List<?>)l;       
    }

handleRowValues这个函数,在以前的版本是private的。

参考了下面的url,但是他们都没给出答案
                 //http://www.codeproject.com/Tips/372152/Mapping-JDBC-ResultSet-to-Object-using-Annotations
                //http://resultsetmapper.sourceforge.net
                //http://nvry.iteye.com/blog/876076
                //http://stackoverflow.com/questions/32756530/how-to-use-mybatis-to-map-values-from-resultset-to-pojo

2016年8月24日星期三

spring aop vs aspectj

AspectJ是编译期间修改代码,属于静态编入,不需要代理类。spring aop基于代理的,用的是aopalliance(aopalliance只是一个规范接口,不是实现),是运行期间植入,是动态植入,没自己的代理,得通过cglib或者jdk代理实现。jdk的出发实现了interface的object,缺不能促发没有实现任何interface的object。如果设置了proxy-target-class="true",就可以用cglib去触发。

静态编入 比 动态编入 应该效率好一些。  spring-aop不好用,没有注解,所以搞出来spring-aspects, 靠注解就能搞定,spring-aspects其实和AspectJ没有任何关系,没有用到aspect的实现,只是用了AspectJ的类定义,所以它不是编译植入,而是动态植入,所以也需要代理实现(jdk或者cglib)


http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-proxying
这个proxy-target-class,虽然可以在好几个个地方设置,但是其实只要设置一个地方,就影响到所有,也就是只要一个地方设置为true,那么就都是true。
<aop:config proxy-target-class="true"/>
<aop:aspectj-autoproxy proxy-target-class="true">
<tx:annotation-driven proxy-target-class="true"/> 
<task:annotation-driven proxy-target-class="true"/>
<cache:annotation-driven proxy-target-class="true/>
 ...

文档是这么写的,既然都是一票定,为啥还要搞一个
ScopedProxyMode?
proxyMode = ScopedProxyMode.TARGET_CLASS还能以bean单位进行的定义? 


找了个文章
http://www.udpwork.com/item/15373.html 

这个文字的意思
>>这个的答案是,aspectj虽然是静态,但spring-aspectj还是动态。用了@Aspectj注释的,就算method不是public的,也起作用,就多这么一个好处+可以不xml而可以注解来设置? 如果只是这样,@Aspectj用处就不算啥了。
 

2016年8月16日星期二

编译podofo时的错误

无论编译成静态还是动态,都会报
/home/advuser/src/lib/comm/pdf/podofo-src/src/base/PdfMemoryManagement.cpp:133: error: ‘SIZE_MAX’ was not declared in this scope,查看/usr/include/stdint.h的代码,

#if !defined __cplusplus || defined __STDC_LIMIT_MACROS
...
#  define SIZE_MAX              (18446744073709551615UL)
# else
#  define SIZE_MAX              (4294967295U)
# endif
...
#endif

#if !defined __cplusplus || defined __STDC_CONSTANT_MACROS
#endif

也就是得先定义__STDC_LIMIT_MACROS再include stdint.h。

那么就修改cmake的podofo_src下面的CMakeLists.txt,追加上

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS")

就OK了。

2016年8月14日星期日

typescript 2.0

https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/tutorials/ASP.NET%20Core.html

https://zhuanlan.zhihu.com/p/21629069

2016年8月7日星期日

sa弄长些,弄频繁些

默认是是10分钟一采集
cat /etc/cron.d/sysstat
*/10 * * * * root /usr/lib64/sa/sa1 1 1
把10修改为1,就变成一分钟了。

默认是保留7天,
cat /etc/sysconfig/sysstat
# How long to keep log files (in days).
# If value is greater than 28, then log files are kept in
# multiple directories, one for each month.
HISTORY=7
把7修改为27就可以

2016年8月4日星期四

angualr multi lang

https://www.sitepoint.com/multilingual-support-for-angularjs/

2016年8月3日星期三

why react

https://medium.freecodecamp.com/angular-2-versus-react-there-will-be-blood-66595faafd51#.fqz71jrb6


2016年8月1日星期一

oracle的并行查询

parallel_server不是并行查询用的,是给RAC用的,和并行查询没有一毛钱关系,这个糊涂了一下。


一般下面几个参数调节,hint里面的并行是会起作用的,就算table自身没有并行。
parallel_degree_policy
parallel_max_servers
parallel_min_servers
parallel_servers_target


测试如下
1.先disable并行
ALTER TABLE SKADVUSER.AD_ORDER_LEADINFO NOPARALLEL;
2 SELECT * FROM AD_ORDER,看计划,没有PX msg pool相关的东西。
3. select /*+ parallel(o 2) */ * from ad_order o,看机会,有了px。

还有个法子,就是直接enable session的并行,
alter session force parallel query;

不要并行
用no_parallel,或者直接将 parallel_max_servers设置为0。
parallel_degree_polic默认是manual,所以,如果表设置了并行,还是会并行。

http://m.blog.itpub.net/9240380/viewspace-1806660/
http://oracleinaction.com/statement-queueing/
http://blog.csdn.net/tianlesoftware/article/details/5854583