File tree Expand file tree Collapse file tree
tool-java-hotcode/src/main/java/com/wdbyte/hotcode Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ public class HotCode {
2222 public static void main (String [] args ) {
2323 // 模拟 CPU 过高
2424 cpuHigh ();
25- // 生成大长度数组
25+ // 不断新增 BigDecimal 信息到 list
2626 allocate ();
2727 // 模拟线程死锁
2828 deadThread ();
@@ -49,36 +49,21 @@ private static void cpuHigh() {
4949 });
5050 thread .start ();
5151 }
52- private static Object array ;
5352
5453 /**
55- * 生成大长度数组
54+ * 不断新增 BigDecimal 信息到 list
5655 */
5756 private static void allocate () {
58- new Thread (() -> {
59- Thread .currentThread ().setName ("memory_allocate_thread_1" );
60- int index = 1 ;
61- while (true ) {
62- array = new BigDecimal [1 * index * 1000 ];
63- try {
64- Thread .sleep (1000 );
65- } catch (InterruptedException e ) {
66- throw new RuntimeException (e );
67- }
68- index ++;
69- }
70- }).start ();
71-
7257 new Thread (()->{
73- Thread .currentThread ().setName ("memory_allocate_thread_2 " );
74- List <String > list = new ArrayList <>();
75- for (int i = 0 ; i < 1000000 ; i ++) {
58+ Thread .currentThread ().setName ("memory_allocate_thread " );
59+ List <BigDecimal > list = new ArrayList <>();
60+ for (int i = 0 ; i < Integer . MAX_VALUE ; i ++) {
7661 try {
7762 Thread .sleep (1 );
7863 } catch (InterruptedException e ) {
7964 throw new RuntimeException (e );
8065 }
81- list .add ("string" + i );
66+ list .add (new BigDecimal ( i ) );
8267 }
8368 }).start ();
8469 }
You can’t perform that action at this time.
0 commit comments