Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Which is better, Beans or Utils, in JAVA?

Shulou Source: shulou.com Published: 2022-06-01 20:32:52 10月02日 Update

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!

Tags: Learning content performance quantity level that is ideas situations data articles logs more knowledge knowledge points articles follow or questions references practice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Docker Microsoft NVidia