File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
chainbase/src/main/java/org/tron/core/capsule
framework/src/test/java/org/tron/core/capsule Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ public class BlockCapsule implements ProtoCapsule<Block> {
5656
5757 private Block block ;
5858 private List <TransactionCapsule > transactions = new ArrayList <>();
59- private StringBuilder toStringBuff = new StringBuilder ();
6059 private boolean isSwitch ;
6160 @ Getter
6261 @ Setter
@@ -314,7 +313,7 @@ public boolean hasWitnessSignature() {
314313
315314 @ Override
316315 public String toString () {
317- toStringBuff . setLength ( 0 );
316+ StringBuilder toStringBuff = new StringBuilder ( );
318317
319318 toStringBuff .append ("BlockCapsule \n [ " );
320319 toStringBuff .append ("hash=" ).append (getBlockId ()).append ("\n " );
Original file line number Diff line number Diff line change 22
33import com .google .protobuf .ByteString ;
44import java .io .IOException ;
5+ import java .util .ArrayList ;
56import java .util .Arrays ;
7+ import java .util .List ;
68import lombok .extern .slf4j .Slf4j ;
79import org .junit .AfterClass ;
810import org .junit .Assert ;
@@ -146,4 +148,20 @@ public void testGetTimeStamp() {
146148 Assert .assertEquals (1234L , blockCapsule0 .getTimeStamp ());
147149 }
148150
151+ @ Test
152+ public void testConcurrentToString () throws InterruptedException {
153+ List <Thread > threadList = new ArrayList <>();
154+ int n = 10 ;
155+ for (int i = 0 ; i < n ; i ++) {
156+ threadList .add (new Thread (() -> blockCapsule0 .toString ()));
157+ }
158+ for (int i = 0 ; i < n ; i ++) {
159+ threadList .get (i ).start ();
160+ }
161+ for (int i = 0 ; i < n ; i ++) {
162+ threadList .get (i ).join ();
163+ }
164+ Assert .assertTrue (true );
165+ }
166+
149167}
You can’t perform that action at this time.
0 commit comments