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;
}
+ /**
+ * 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>();
/**
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;
}