Closed tisonkun closed 5 years ago
To reduce the allocation and release of memory, some fragments are not done in the same way as below. It isn't a problem if the code location is not the main process.
public void reCreateIndexFiles() {
final StringBuilder sBuilder = new StringBuilder(512);
try {
loadDataSegments(sBuilder);
deleteIndexFiles(sBuilder);
createIndexFiles();
} catch (Throwable ee) {
sBuilder.delete(0, sBuilder.length());
logger.error(sBuilder.append("ReCreate Index File of ")
.append(this.topicKey).append(" error ").toString(), ee);
}
}
减少内存的分配与释放, 部分片段如果没有按照如上同一的方式去做, 只要代码位置不是主干流程,问题不大
@gosonzhang
Thanks for your explanation.
FYI https://www.jianshu.com/p/4518359da254 & https://dzone.com/articles/string-concatenation-performacne-improvement-in-ja
Maybe it is valid to replace StringBuilder
usage above with string concatenation for readability in non-performance-sensitive scenario.
Notice there are lots of string concatenations following style
which can be transferred to
I don't know the reason that we adopt the first style but it seems counter-intuitive.
CC @gosonzhang