File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
chainbase/src/main/java/org/tron/core/capsule
framework/src/test/java/org/tron/core/actuator/utils Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,6 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {
102102 @ Setter
103103 private TransactionTrace trxTrace ;
104104
105- private StringBuilder toStringBuff = new StringBuilder ();
106105 @ Getter
107106 @ Setter
108107 private long time ;
@@ -738,7 +737,7 @@ public Transaction getInstance() {
738737
739738 @ Override
740739 public String toString () {
741-
740+ StringBuilder toStringBuff = new StringBuilder ();
742741 toStringBuff .setLength (0 );
743742 toStringBuff .append ("TransactionCapsule \n [ " );
744743
Original file line number Diff line number Diff line change 1414
1515import com .google .protobuf .ByteString ;
1616import java .nio .charset .StandardCharsets ;
17+ import java .util .ArrayList ;
1718import java .util .List ;
1819import lombok .extern .slf4j .Slf4j ;
1920import org .junit .Assert ;
@@ -431,4 +432,22 @@ public void estimateConsumeBandWidthSizeCorner() {
431432 long actual = TransactionUtil .estimateConsumeBandWidthSize (dps , balance );
432433 Assert .assertEquals (expected , actual );
433434 }
435+
436+ @ Test
437+ public void testConcurrentToString () throws InterruptedException {
438+ Transaction .Builder builder = Transaction .newBuilder ();
439+ TransactionCapsule trx = new TransactionCapsule (builder .build ());
440+ List <Thread > threadList = new ArrayList <>();
441+ int n = 10 ;
442+ for (int i = 0 ; i < n ; i ++) {
443+ threadList .add (new Thread (() -> trx .toString ()));
444+ }
445+ for (int i = 0 ; i < n ; i ++) {
446+ threadList .get (i ).start ();
447+ }
448+ for (int i = 0 ; i < n ; i ++) {
449+ threadList .get (i ).join ();
450+ }
451+ Assert .assertTrue (true );
452+ }
434453}
You can’t perform that action at this time.
0 commit comments