2013-10-08 51 views
3

我使用杰克逊将Java POJO转换为JSON字符串。我面临的问题是随着请求数量的增加,处理转换的时间开始增加。例如,对于100tps,处理所用的时间为10ms,但在2000tps时,所花费的时间为90ms。我怎样才能避免它?有没有办法让它独立于tps。杰克逊将对象转换为json字符串

+0

如果它可能缓存你的结果json –

+0

我无法缓存它。这将是一个新的每一个 – Abhi

回答

0

请提供您使用的代码,否则很难对其进行优化。

还有其他序列化选项和JSON框架可用。如果你想保留JSON,寻找其他框架,如“json-smart”:http://code.google.com/p/json-smart/ 他们声称比Jackson快2-3倍。

+0

我使用的代码如下ObjectMapper mapper = new ObjectMapper(); \t \t String json = null; \t \t AnnotationIntrospector primary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); \t \t AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); \t \t AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary,secondary); \t \t mapper.setAnnotationIntrospector(pair); \t \t \t尝试{ \t \t \t \t JSON = mapper.writeValueAsString(OBJ); \t \t \t \t \t \t \t \t \t}赶上(例外五){ \t \t \t \t返回 “无法转换为JSON对象:” + obj.toString()+ “的消息:” + e.getMessage() ; \t \t \t \t \t \t \t} – Abhi

+0

您应该能够回收对象映射,这可能会提高性能。 – Thomas

+0

如何重新映射对象映射器? – Abhi

相关问题