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> {
56
56
57
57
private Block block ;
58
58
private List <TransactionCapsule > transactions = new ArrayList <>();
59
- private StringBuilder toStringBuff = new StringBuilder ();
60
59
private boolean isSwitch ;
61
60
@ Getter
62
61
@ Setter
@@ -314,7 +313,7 @@ public boolean hasWitnessSignature() {
314
313
315
314
@ Override
316
315
public String toString () {
317
- toStringBuff . setLength ( 0 );
316
+ StringBuilder toStringBuff = new StringBuilder ( );
318
317
319
318
toStringBuff .append ("BlockCapsule \n [ " );
320
319
toStringBuff .append ("hash=" ).append (getBlockId ()).append ("\n " );
Original file line number Diff line number Diff line change 2
2
3
3
import com .google .protobuf .ByteString ;
4
4
import java .io .IOException ;
5
+ import java .util .ArrayList ;
5
6
import java .util .Arrays ;
7
+ import java .util .List ;
6
8
import lombok .extern .slf4j .Slf4j ;
7
9
import org .junit .AfterClass ;
8
10
import org .junit .Assert ;
@@ -146,4 +148,20 @@ public void testGetTimeStamp() {
146
148
Assert .assertEquals (1234L , blockCapsule0 .getTimeStamp ());
147
149
}
148
150
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
+
149
167
}
You can’t perform that action at this time.
0 commit comments