JAVA中Beans与Utils哪个更好
这篇文章主要讲解了“JAVA中Beans与Utils哪个更好”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“JAVA中Beans与Utils哪个更好”吧!
目前创新互联已为近千家的企业提供了网站建设、域名、网络空间、网站托管维护、企业网站设计、东城网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
1.apache BeanUtils 性能太差 日志太多
2.Apache PropertyUtils 性能可以参考,但是数据量大了比起Cglib 还是慢很多
3.Spring BeanUtils 上了一定的数量级别比较慢
4.Cglib BeanCopier 目前看来比较稳定
5.com.rits.cloning ,数量级别大了 也慢
package com.helloxin.restful.api; import com.helloxin.restful.api.bo.CarBO; import com.rits.cloning.Cloner; import lombok.extern.slf4j.Slf4j; import net.sf.cglib.beans.BeanCopier; import org.apache.commons.beanutils.PropertyUtils; import org.junit.Test; import org.springframework.beans.BeanUtils; import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; @Slf4j public class BeanCopyTest { final static public Integer NUM = 10000; @Test public void beanSpringCopyTest() { Listlist = createData(NUM); long start = System.currentTimeMillis(); for(int i = 0;i< NUM;i++){ CarBO newCar = new CarBO(); BeanUtils.copyProperties(list.get(i), newCar); } log.info("duration={}", System.currentTimeMillis() - start); } @Test public void beanCglibCopyTest() { List list = createData(NUM); long start = System.currentTimeMillis(); BeanCopier b = BeanCopier.create(CarBO.class, CarBO.class, false); for(int i = 0;i< NUM;i++){ CarBO newCar = new CarBO(); b.copy(list.get(i), newCar, null); } log.info("duration={}", System.currentTimeMillis() - start); } @Test public void beanApacheCopyTest() throws InvocationTargetException, IllegalAccessException { List list = createData(NUM); long start = System.currentTimeMillis(); BeanCopier b = BeanCopier.create(CarBO.class, CarBO.class, false); for(int i = 0;i< NUM;i++){ CarBO newCar = new CarBO(); org.apache.commons.beanutils.BeanUtils.copyProperties(newCar,list.get(i)); } log.info("duration={}", System.currentTimeMillis() - start); } @Test public void beanApachePropertyUtilsCopyTest() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { List list = createData(NUM); long start = System.currentTimeMillis(); BeanCopier b = BeanCopier.create(CarBO.class, CarBO.class, false); for(int i = 0;i< NUM;i++){ CarBO newCar = new CarBO(); PropertyUtils.copyProperties(newCar,list.get(i)); } log.info("duration={}", System.currentTimeMillis() - start); } @Test public void beanRitsCloningTest() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { List list = createData(NUM); long start = System.currentTimeMillis(); Cloner cloner = new Cloner(); for(int i = 0;i< NUM;i++){ cloner.deepClone(list.get(i)); } log.info("duration={}", System.currentTimeMillis() - start); } private CarBO createData() { return CarBO.builder().make("st").numberOfSeats(12).build(); } private List createData(int num) { return IntStream.range(0, num).mapToObj(i -> CarBO.builder().make("st").numberOfSeats(i).build()).collect(Collectors.toList()); } }
感谢各位的阅读,以上就是“JAVA中Beans与Utils哪个更好”的内容了,经过本文的学习后,相信大家对JAVA中Beans与Utils哪个更好这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
本文题目:JAVA中Beans与Utils哪个更好
本文地址:http://ybzwz.com/article/jdocjc.html