在Spring bean服务[@service]类中创建类级别的String变量。
在整个类中重用该引用变量,以不同的方法更新String对象。
对于较小的字符串[15 MB],这是好的设计还是不好的设计。
@service
Class XYZService {
private String generatedOutput;
public String method1 {
generatedOutput = "xyz";
method2();
method3();
return generatedOutput;
}
private void method2() {
/*
* Some processing logic here and create StringBuilder object
* StringBuilder strBuild = new StringBuilder();
*/
generatedOutput = strBuild.toString();
}
private void method3() {
/*
* Some processing logic here and create StringBuilder object
* StringBuilder strBuild = new StringBuilder();
*
*/
generatedOutput = strBuild.toString();
}
}