You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/07/31 02:51:51 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2646] fix metaspace oom problem (#3238)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 2388f7bf2 [SCB-2646] fix metaspace oom problem (#3238)
2388f7bf2 is described below
commit 2388f7bf263e4ea38f1c35afece6d453a0d9e9fb
Author: yanghao <73...@users.noreply.github.com>
AuthorDate: Sun Jul 31 10:51:45 2022 +0800
[SCB-2646] fix metaspace oom problem (#3238)
---
.../servicecomb/config/priority/ConfigObjectFactory.java | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
index ecedf2648..7bec69d76 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
@@ -26,7 +26,9 @@ import java.util.Map;
import org.apache.servicecomb.config.inject.InjectProperties;
import org.apache.servicecomb.config.inject.InjectProperty;
import org.apache.servicecomb.config.inject.PlaceholderResolver;
+import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
+import org.apache.servicecomb.foundation.common.utils.LambdaMetafactoryUtils;
import org.apache.servicecomb.foundation.common.utils.bean.Setter;
import org.springframework.stereotype.Component;
@@ -45,7 +47,9 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
@Component
public class ConfigObjectFactory {
private final PriorityPropertyFactory propertyFactory;
-
+ private static final Map<Class<?>, JavaType> classCache = new ConcurrentHashMapEx<>();
+ private static final Map<JavaType, BeanDescription> javaTypeCache = new ConcurrentHashMapEx<>();
+ private static final Map<BeanPropertyDefinition, Setter<Object, Object>> beanDescriptionCache = new ConcurrentHashMapEx<>();
public ConfigObjectFactory(PriorityPropertyFactory propertyFactory) {
this.propertyFactory = propertyFactory;
}
@@ -84,8 +88,9 @@ public class ConfigObjectFactory {
public List<ConfigObjectProperty> createProperties(Object instance, String prefix, Map<String, Object> parameters) {
List<ConfigObjectProperty> properties = new ArrayList<>();
- JavaType javaType = TypeFactory.defaultInstance().constructType(instance.getClass());
- BeanDescription beanDescription = JsonUtils.OBJ_MAPPER.getSerializationConfig().introspect(javaType);
+ JavaType javaType = classCache.computeIfAbsent(instance.getClass(), TypeFactory.defaultInstance()::constructType);
+ BeanDescription beanDescription = javaTypeCache.computeIfAbsent(javaType,
+ JsonUtils.OBJ_MAPPER.getSerializationConfig()::introspect);
for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
if (propertyDefinition.getField() == null) {
continue;
@@ -95,7 +100,8 @@ public class ConfigObjectFactory {
continue;
}
- Setter<Object, Object> setter = createObjectSetter(propertyDefinition);
+ Setter<Object, Object> setter = beanDescriptionCache.computeIfAbsent(propertyDefinition,
+ LambdaMetafactoryUtils::createObjectSetter);
PriorityProperty<?> priorityProperty = createPriorityProperty(propertyDefinition.getField().getAnnotated(),
prefix, parameters);
setter.set(instance, priorityProperty.getValue());
@@ -205,7 +211,7 @@ public class ConfigObjectFactory {
private String[] collectPropertyKeys(Field field, String prefix, Map<String, Object> parameters) {
String propertyPrefix = prefix;
- String[] keys = new String[] {field.getName()};
+ String[] keys = new String[]{field.getName()};
InjectProperty injectProperty = field.getAnnotation(InjectProperty.class);
if (injectProperty != null) {