diff options
author | Artur Signell <artur@vaadin.com> | 2013-01-21 17:36:04 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-01-21 17:36:04 +0000 |
commit | c21d29f7b1168f23c4ff98f5dc9e9e65458b1a14 (patch) | |
tree | 6593f7220d22a2dad2742230440a9a807e8d43a2 /server/src/com/vaadin | |
parent | 42230440620e69e1f249607770bd0d4cb974bd59 (diff) | |
parent | 54a8cd0e435604a7b4273850d0bdb4bd1bc1a46b (diff) | |
download | vaadin-framework-c21d29f7b1168f23c4ff98f5dc9e9e65458b1a14.tar.gz vaadin-framework-c21d29f7b1168f23c4ff98f5dc9e9e65458b1a14.zip |
Merge "Cache state type property definitions (#10781)"
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r-- | server/src/com/vaadin/server/JsonCodec.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/server/src/com/vaadin/server/JsonCodec.java b/server/src/com/vaadin/server/JsonCodec.java index b9cdcf5a87..9a70efab28 100644 --- a/server/src/com/vaadin/server/JsonCodec.java +++ b/server/src/com/vaadin/server/JsonCodec.java @@ -38,6 +38,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import org.json.JSONArray; import org.json.JSONException; @@ -158,6 +160,14 @@ public class JsonCodec implements Serializable { } + /** + * Cache the collection of bean properties for a given type to avoid doing a + * quite expensive lookup multiple times. Will be used from any thread that + * happens to process Vaadin requests, so it must be protected from + * corruption caused by concurrent access. + */ + private static ConcurrentMap<Class<?>, Collection<BeanProperty>> typePropertyCache = new ConcurrentHashMap<Class<?>, Collection<BeanProperty>>(); + private static Map<Class<?>, String> typeToTransportType = new HashMap<Class<?>, String>(); /** @@ -682,11 +692,18 @@ public class JsonCodec implements Serializable { public static Collection<BeanProperty> getProperties(Class<?> type) throws IntrospectionException { + Collection<BeanProperty> cachedProperties = typePropertyCache.get(type); + if (cachedProperties != null) { + return cachedProperties; + } Collection<BeanProperty> properties = new ArrayList<BeanProperty>(); properties.addAll(MethodProperty.find(type)); properties.addAll(FieldProperty.find(type)); + // Doesn't matter if the same calculation is done multiple times from + // different threads, so there's no need to do e.g. putIfAbsent + typePropertyCache.put(type, properties); return properties; } |