Operation management of java entering the pit

1. Overview

1.1Java development and operation process

  • Writing stage: Use various editing tools to write .java files
  • Compilation stage: Use javac.exe to compile java files and generate .class files
  • Running phase: Use java.exe to load the .class file and run it

Detailed process

1.2 related concepts

javaOS management

JavaOS is an operating system based on the Java language. Its management mainly involves the following aspects:

1. Resource management: JavaOS needs to manage various resources on the computer, such as memory, disk space, CPU, etc. The operating system needs to coordinate these resources so that they can be used efficiently by applications.

2. Process management: JavaOS needs to manage various applications running on the computer, which are composed of multiple processes. The operating system needs to manage these processes, allocate resources to them, control their execution order and time slices, etc.

3. File system management: JavaOS needs to manage the file system on the computer, including file creation, reading, writing, deletion and other operations. The operating system needs to maintain the directory structure of files to ensure the integrity and security of the file system.

4. Network management: JavaOS needs to manage network resources on the computer, such as network cards, network connections, etc. The operating system needs to provide network services, such as TCP/IP protocol stack, network file sharing, etc.

5. Device driver management: JavaOS needs to manage various device drivers on the computer, such as printer drivers, audio drivers, etc. The operating system needs to ensure the correctness and stability of device drivers.

The above are several aspects of JavaOS management, the most important of which are resource management and process management, because they directly affect the performance and stability of the operating system.

java JVM management

JVM is the environment responsible for compiling Java programs into bytecode and interpreting and executing them. The JVM also provides memory management, garbage collection, thread management and other services for programs.

Following are some important aspects of JVM management:

1. Memory management: JVM allocates memory space for the program and dynamically allocates more memory when needed. It is also responsible for releasing memory that is no longer used to prevent programs from leaking memory and crashing.

2. Garbage collection: JVM will automatically monitor the memory usage of the program and automatically clean up memory space that is no longer used when necessary. This is called garbage collection. Garbage collection ensures that programs do not waste memory and avoid memory leaks.

3. Thread management: The JVM manages the program’s threads, ensuring that they run at the correct time, and coordinating shared resources between them. The JVM can detect thread deadlocks and infinite loops and take steps to avoid these problems.

4. Class loading: JVM is responsible for loading the classes used in the program into memory so that its methods can be executed.

5. Execution Engine: JVM also has an execution engine, which interprets bytecode and converts it into machine code so that it can be run on the computer.

JVM management is crucial for the proper functioning of Java programs, so developers need to ensure that programs are optimized to reduce memory usage and resource consumption during development.

2. OS management

2.1 Overview of management commands

2.2top command

The commands are described in detail in the Linux chapter and will not be described in detail here.

The Linux top command is used to display process dynamics in real time, such as CPU usage, memory usage, number of processes and other information. The following are commonly used top command options and parameters:

– -d : Set the time interval for the top command to update process information.
– -H: Display the thread information of the process.
– -p : Only display information about the specified process.
– -u : Only display process information of the specified user.
– -i: Do not display idle processes (IDLE).
– -c: Display complete command line information.
– -b: Run in batch mode and output the results to a file.

Interactive command of top command:

-d: Change the refresh interval.
-q: Exit the top command.
-k: Kill the specified process.
-r: Modify the priority of the specified process.
-s: Change the display mode of the top command, you can choose to sort by CPU usage or memory usage.
-h: View help information.

2.3vmstat command

The vmstat (virtual memory statistics) command is a powerful system performance analysis tool that is widely used in Linux systems. The vmstat command can display system performance information such as virtual memory, processes, and CPU activity. The following is a detailed introduction to the vmstat command.

Command format:

vmstat [options] [time interval] [number of repetitions]

Common options:

– -a: Display details of active and inactive memory.
– -d: Display disk activity information.
– -p: Display process details.
– -s: Display system memory statistics.

Time interval and number of repetitions: used to specify the time interval and number of times the command is displayed. The default time interval is 1 second and the number of repetitions is unlimited. You can stop command execution by using Ctrl + C or specify the number of repetitions.

Explanation of vmstat command output results:

– r: Number of processes waiting to run.
– b: Number of processes in non-interruptible or interruptible sleep state.
– swpd: swap memory usage.
– free: the amount of free memory.
– buff: the amount of cache memory.
– cache: The amount of cache memory.
– si: The amount of data swapped from disk to memory per second.
– so: The amount of data swapped from memory to disk per second.
– bi: Number of blocks read from disk per second.
– bo: Number of blocks written to disk per second.
– in: number of interrupts per second.
-cs: Number of CPU context switches per second.
– us: The percentage of CPU time consumed by user space programs.
– sy: The percentage of CPU time consumed by kernel space programs.
– id: CPU idle time percentage.
– wa: The percentage of CPU time waiting for I/O operations to complete.

2.4iostat command

2.5windows task manager

2.6 perfmon tool

2.7 further

3. JDK management tool (JVM management)

3.1 Tool Overview


3.2jps tool

jps (Java Virtual Machine Process Status Tool) is a command line tool used to display the process ID (PID) and class name of a running Java process. The jps tool can be used to quickly find running Java processes for debugging or monitoring purposes. The usage of jps command is as follows:

jps [-q] [-m] [-l] [-v]

Among them, -q displays only the process ID, -m displays the process ID and program name, -l displays the process ID and fully qualified program class name, and -v displays the process ID, fully qualified program class name, and parameters passed to the JVM. By default, jps displays the process ID and program name.

.3.3jstat tool

jstat is a tool command in Java that can be used to monitor various status and performance indicators of the JVM. Use the jstat command to view the JVM’s heap memory usage, GC status, class loading status, etc. in real time, which can help developers locate application performance problems and optimize JVM configuration.

The syntax format of the jstat command is as follows:

jstat [ generalOption | outputOptions vmid [interval[s|ms] [count]] ]

Among them, generalOption represents general options, outputOptions represents output options, vmid represents the JVM process ID that needs to be monitored, interval represents the monitoring time interval, and count represents the number of monitoring times.

Commonly used jstat command options include:

– -gc: Display JVM garbage collection heap information;
– -class: Displays information about JVM loaded classes;
– -compiler: Displays JVM just-in-time compiler (JIT) information;
– -gcutil: Display JVM garbage collection statistics;
– -gccapacity: Display JVM heap memory usage.

For example, the following command can monitor the garbage collection heap information, garbage collection statistics, and heap memory usage for process ID 1234 once per second:

jstat -gc -gcutil -gccapacity 1234 1s

3.4 jinfo tool

The Java jinfo tool is one of the Java diagnostic command line tools that can be used to view and adjust parameters of running Java applications. jinfo can print out basic information about the Java application process, such as startup parameters, system properties, Java virtual machine configuration, etc.

The syntax of the jinfo tool is as follows:

jinfo [options] <pid>

Among them, `` is the process ID of the Java process, and `options` are optional parameters, including:

– `-flag `: View the value of the specified JVM parameter.
– `-flags`: View the current values of JVM parameters.
– `-sysprops`: View the values of Java system properties.

For example, to view the -Xmx parameter value in the startup parameters of the Java process with process number 12345, you can use the following command:

jinfo -flag Xmx 12345

To view the values of all parameters currently set by the Java process with process number 12345, you can use the following command:

jinfo -flags 12345

To view all system property values of the Java process with process number 12345, you can use the following command:

jinfo -sysprops 12345

3.5jstack tool

Java jstack is a command line tool for viewing thread stack information of Java applications. It helps developers diagnose threading issues and deadlock issues in applications.

To use jstack, you need to enter the following commands on the command line:

jstack [pid]

where pid is the process ID of the Java application. This will print out the stack trace information for all threads in the application.

You can use the following command to dump the output of jstack to a file:

jstack [pid] > [filename]

In the generated file, you can use a text editor or other tool to view thread stack information.

3.6jstatd tool

Java jstatd is a Java tool used to monitor the performance of Java Virtual Machine (JVM) on a remote host. It runs in a separate process and can connect to a JVM running on a remote host and collect performance information about that JVM. jstatd can run locally or remotely, and can be configured and managed via Java Management Extensions (JMX).

jstatd is commonly used to monitor the performance and behavior of Java applications for tuning and optimization. It can provide information about JVM memory usage, thread stack, garbage collector activity and class loader usage.

To use the jstatd tool, JDK (Java Development Kit) must be installed. You can then run jstatd using the following command:

jstatd [-options] [hostid]

Among them, the options include:

– -Joption: Pass options to the Java virtual machine.
– -p port: Specify the port number of the jstatd process.
– -n: Specifies that the jstatd process should accept connections from all remote hosts.
– -r: Specifies that the jstatd process should accept SSL connections from all remote hosts.

The hostid parameter specifies the hostname or IP address of the remote host to be monitored. If hostid is not specified, jstatd will run locally and the local JVM can be accessed via JMX.

Once jstatd is running, you can use the jstat command to connect and query JVM performance data. For example, you can query JVM memory usage using the following command:

jstat -gcutil <remote_host>:<port> <interval> <count>

Among them, remote_host is the host name or IP address of the remote host where the jstatd process is located, port is the port number of the jstatd process, interval is the query interval (in milliseconds), and count is the number of queries. This command will return the JVM’s garbage collector usage, including information such as heap size, used heap space, and garbage collector usage.

In summary, the Java jstatd tool is a very useful tool that can be used to monitor and optimize the performance of Java applications.

3.7jcmd tool

jcmd is a command line tool introduced in JDK 7 that can be used to manage Java applications. It lists running Java processes and the diagnostic and debugging-related commands supported by these processes. The following are some commonly used jcmd commands:

1. List all running Java processes:

jcmd -l

2. Display the command list of a Java process:

jcmd help

3. Display the JVM properties of a Java process:

jcmd VM.system_properties

4. View the thread information of a Java process:

jcmd Thread.print

5. View the heap information of a Java process:

jcmd GC.heap_info

These commands are only part of jcmd, there are many other commands available. You can use the “jcmd -help” command to list all available commands.

4. Visual management tools

4.1JConsole tool


Details

4.2VM Tools

detailed

4.3Mission Control


5. Heap file analysis


5.1jmap command

The jmap command is a tool that comes with Java. It is used to obtain a memory snapshot of the Java process. It can view object information, class information, thread information, GC information, etc. in the Java heap. Common uses include:

1. Use jmap -heap pid to check the memory usage of the Java process;
2. Use jmap -dump:format=b,file=heap.bin pid to dump the heap memory of the Java process into a file to facilitate subsequent offline analysis;
3. Use jmap -histo pid to check the number of instances and memory usage of each class in the Java process;
4. Use jmap -permstat pid to check the status of the permanent generation (PermGen or Metaspace) in the Java process.

It should be noted that jmap will trigger Full GC when obtaining a memory snapshot, which may have an impact on application performance, so it is recommended to use the jmap command only when necessary.

5.2jhat command (disappeared)

jhat is a command line tool that comes with the Java SE Development Kit (JDK) and is used to generate and analyze Java heap dump files. It loads the heap dump file into memory and allows users to view the information of objects, classes, instances and references contained in the Java heap dump file in the browser.

Using the jhat command can help developers or operation and maintenance personnel quickly diagnose memory problems in Java applications and locate memory leaks or memory overflows.

For example, the jhat command can be used in the following way:

1. Generate Java heap dump file:

jmap -dump:live,format=b,file=<filename>.hprof <PID>

2. Use the jhat command to load and parse the Java heap dump file:

jhat <filename>.hprof

3. Visit http://localhost:7000/ in the browser and browse the information in the Java heap dump file.

6. JMX

6.1 Overview

JMX (Java Management Extensions) is a standardized way to manage and monitor applications, devices, systems and network services on the Java platform. JMX provides a standard way to manage Java applications and can be easily integrated into existing management tools.

Java applications can expose their own management interfaces using the JMX API, which can be connected and used by remote clients. The JMX API provides access to MBeans (Managed Beans) in the application, which are standard Java objects used to represent the components and state of the application. The JMX API also provides a way to

6.2JMX architecture

6.3MBean

6.4Agent


6.5 Advantages

7. Java program operation is safe

·Java programs come from complex sources

  1. custom class
  2. Third-party Jar package
  3. Network download (Applet,.RMI, etc.)

·Java program running

  1. Illegal access to certain directories
  2. Open Socket link
  3. Exit virtual machine

Related codes

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Java Skill TreeHomepageOverview 138826 people are learning the system