Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Which is better, Beans or Utils, in JAVA?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "which is better, Beans or Utils in JAVA". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "which is better, Beans or Utils in JAVA".

1.apache BeanUtils performance is too poor and there are too many logs

The performance of 2.Apache PropertyUtils can be referred to, but the amount of data is still much slower than that of Cglib.

It is slow to have a certain quantity level on 3.Spring BeanUtils

4.Cglib BeanCopier seems to be stable at present.

5.com.rits.cloning, if the quantity level is large, it is slow.

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;@Slf4jpublic class BeanCopyTest {final static public Integer NUM = 10000 @ Test public void beanSpringCopyTest () {List list = createData (NUM); long start = System.currentTimeMillis (); for (int I = 0 Tinci

< 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 () .numbers (Collectors.toList ());}} Thank you for your reading, this is the content of "which is better, Beans or Utils in JAVA". After the study of this article, I believe you have a deeper understanding of which is better in JAVA, and the specific use needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report