diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-01-18 11:25:45 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2013-01-18 11:26:11 +0200 |
commit | 54a8cd0e435604a7b4273850d0bdb4bd1bc1a46b (patch) | |
tree | 1b17bc767eec915235af3bf98e5a0358f3823713 /server/src | |
parent | ac00c704f168c99bd7f8c2897f14f9e80f2e95b3 (diff) | |
download | vaadin-framework-54a8cd0e435604a7b4273850d0bdb4bd1bc1a46b.tar.gz vaadin-framework-54a8cd0e435604a7b4273850d0bdb4bd1bc1a46b.zip |
Cache state type property definitions (#10781)
Change-Id: I148c44e98c0a745b1674fbe5da5412845d33cc3d
Diffstat (limited to 'server/src')
-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; } |