现在的代码都是这样的:
public void decrementCounterByPk(String primaryKeyValue, String field) {
BSONObject matcher = new BasicBSONObject();
matcher.put(this.primaryKey, primaryKeyValue);
BSONObject obj = new BasicBSONObject();
BSONObject arg1 = new BasicBSONObject();
arg1.put(field, -1);
obj.put(MatchConst._INC, arg1);
matcher.put(this.primaryKey, primaryKeyValue);
APIHelp.updateJsonObject(dbSpaceName, dbCollectionName, matcher, obj);
}
还有比这个更长的。但是他们都有一个共同的模式,就是BSONObject matcher = new BasicBSONObject();,每一个函数都要生成七八个BSONObject。
这样比如一万次查询,就会生成数十万个BSONObject ,造成GC缓慢。请问有什么模式可以减少BSONObject的生成?但是不影响功能?