“This is the 28th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

1, the Windows

View process information in the task manager

View Java processes on the Process TAB. I started with IDEA, so you can view related processes under IDEA

You can also search for Java by pressing Ctrl+ F on the Details TAB

View process information on the console

Enter CMD and type TaskList to view all process information, including process IDS and memory usage

Check the Java related process, can add filter conditions tasklist | findstr searches “Java,” Windows need to be paid attention to in the string need to use double quotation marks, or without can too

If you want to start the program in IDEA, run the command using the Terminal of IDEA

Taskkill Kills a process

To kill a process, run the taskkill /pid command to specify the process ID. If the process cannot be killed, forcibly kill the taskkill /pid process id -t -f command

You can see that the process in the IDEA console has ended

Through the tasklist | findstr searches process id has been unable to query to the process, that process terminates

2, Linux

The ps -ef command is used to query information

In Linux, you can use ps-ef to view all process information. If you do not know the specific parameter description, you can refer to the simple introduction of the rookie website.

www.runoob.com/linux/linux…

Use timeunit.seconds.sleep (2) to sleep for 2 SECONDS to free up CPU execution time.

Javac threadDemo2.java compiles the threadDemo2.java class to generate the corresponding class file – threadDemo2.class; After through the Java – cp/com. LZB. Concurrency. Not. ThreadDemo2 operation

Ps ThreadDemo2 process information – ef | grep ThreadDemo2 (note that need to open a new Shell window)

Kill Kill a process

Run the kill process ID command to kill the process

Run the top command to view information.

To view information about all processes, run the top command

To view information about the specified process, run the top -p process ID command. To view information about all threads in the specified process, run the top-h-p process ID command

For specific parameter description, please refer to the simple introduction of cainiao website. The following links can be directly used.

www.runoob.com/linux/linux…

3. Java comes with tools

JPS Displays the process ID

Java native commands are platform-neutral, and if you need to see all the Java process ids, you can use JPS

Jstack looks at the thread state in the process

To check the thread status of a Java process, you can use JPS to query the id of the process, and then query the status of all threads in the process by using jSTACK. Note that the thread status queried by jstack is the thread status of the process at the query time (transient).

There’s a lot of information and it’s not all there

Jconsole graphical interface

Jconsole is a graphical interface that comes with the JDK to monitor memory, threads, classes, and other resources.

In Windows, you can double-click the jconsole.exe file in the bin folder of the JDK installation directory

If it is a local Java process, you can check the local process, and then find your Java process in the local process, select and click Connect

Local connection does not require password authentication. You can select an insecure connection. The following is the page of jConsole

If the Java process is running on a remote Linux server, you need to use a remote connection

The remote connection requires information such as IP port USERNAME password. In this case, you need to run the Java class as follows

Java – Djava. Rmi. Server hostname = ‘IP address’ – Dcom. Sun. Management jmxremote – Dcom. Sun. Management jmxremote. Port = ‘port’ – Dcom. Sun. Management. Jmxremote. If SSL = secure connection – Dcom.

Sun. Management. Jmxremote. Authenticate = whether need certified Java classes