springboot jpa查询结果转换成model非常耗时,查了一下,cpu一个核跑满了。
Cpu usage!
Found JVM pid:25370,topThreadHexIds=[ 479e,CPU_Usage:99.9 48a4,CPU_Usage:99.9 2fc,CPU_Usage:5.3 17dc,CPU_Usage:5.3]
------------------------*******0x48a4 CPU_Usage:99.9***********----------------------------
"default task-259" #7794 prio=5 os_prio=0 tid=0x0000565341845000 nid=0x48a4 runnable [0x00007f54b9c81000]
java.lang.Thread.State: RUNNABLE
at java.lang.System.identityHashCode(Native Method)
at java.lang.reflect.WeakCache$LookupValue.hashCode(WeakCache.java:282)
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964)
at java.lang.reflect.WeakCache.containsValue(WeakCache.java:175)
at java.lang.reflect.Proxy.isProxyClass(Proxy.java:791)
at sun.reflect.annotation.AnnotationInvocationHandler.asOneOfUs(AnnotationInvocationHandler.java:225)
at sun.reflect.annotation.AnnotationInvocationHandler.equalsImpl(AnnotationInvocationHandler.java:201)
at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:64)
at com.sun.proxy.$Proxy401.equals(Unknown Source)
at org.springframework.core.convert.TypeDescriptor.annotationEquals(TypeDescriptor.java:504)
at org.springframework.core.convert.TypeDescriptor.annotationsMatch(TypeDescriptor.java:494)
at org.springframework.core.convert.TypeDescriptor.equals(TypeDescriptor.java:468)
at org.springframework.core.convert.support.GenericConversionService$ConverterCacheKey.equals(GenericConversionService.java:471)
at org.springframework.util.ObjectUtils.nullSafeEquals(ObjectUtils.java:329)
at org.springframework.util.ConcurrentReferenceHashMap$Segment.findInChain(ConcurrentReferenceHashMap.java:648)
at org.springframework.util.ConcurrentReferenceHashMap$Segment.getReference(ConcurrentReferenceHashMap.java:504)
at org.springframework.util.ConcurrentReferenceHashMap.getReference(ConcurrentReferenceHashMap.java:265)
at org.springframework.util.ConcurrentReferenceHashMap.get(ConcurrentReferenceHashMap.java:235)
at org.springframework.core.convert.support.GenericConversionService.getConverter(GenericConversionService.java:256)
at org.springframework.core.convert.support.GenericConversionService.canConvert(GenericConversionService.java:146)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:127)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:609)
at org.springframework.beans.AbstractNestablePropertyAccessor.processLocalProperty(AbstractNestablePropertyAccessor.java:458)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:278)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:246)
model类添加@EqualsAndHashCode还是会这样
model的大概结构,@Excel是自己写的一个注解用于excel导出,
@Setter
@Getter
@EqualsAndHashCode(callSuper = true)
public class D extends E{
//仓库
@Excel(name = "仓库", sort = 5, align = HorizontalAlignment.LEFT)
private String c;
//业务类型
private String b;
@Excel(name = "业务类型", sort = 10, align = HorizontalAlignment.LEFT)
private String a;
}
由于查询包是公司框架封装好的,查看源码,发现如果接收的类型如果是Map,查询出来的result不会走属性、注释等校验,而是直接返回。遂换成Map接收,然后自己循环转换成model。