First we write a simple multi-threaded code:
class MyThread extends Thread{
@Override
public void run() {
while (true) {
System.out.println("创建的一个新线程");
//让循环慢一点
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
public class Test {
public static void main(String[] args) {
Thread tmp = new MyThread();
tmp.start();
while (true){
System.out.println("main线程");
//让循环慢一点
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
This code simply creates a new thread and lets the new thread and the old thread print different things respectively.
The following is the text:
Step 1: Run the above code (Note: The code must be running during the following operations)
Step 2: Find the location of the JDK installation
If your coding environment is IDEA and you forget the installation location of JDK, you can refer to the following steps:
Step 3: Enter the bin directory, find jconsole.exe and open it (if nothing is found, try opening it as an administrator)
Step 4: Select the file name where you want to run the code
Step 5: Click Connect and then click Unsafe Connection
Hope the above content can help you.