Detailed description of jboss startup loading process (-)

Source: Internet
Author: User
Tags jboss application server

Today, I checked the boot. log and server. log logs of jboss and summarized the jboss startup and loading processes based on my understanding and other information;

This article takes JBoss Application Server 4.2.1 GA (hereinafter referred to as JBoss) as an example to introduce its startup process on the Windows platform. To facilitate the description, make the following assumptions for the platform environment: the installation path for Java Runtime is C:/Java, and the installation path for JBoss is C:/JBoss.

Since JBoss compiled in 100% Java has the cross-platform feature, why should we emphasize Windows? This is because JBoss is started from the platform-related script files, and the script files on different platforms are different. For example, the script file on Windows is run. bat, and the script on linux is run. sh. The content of the two files is very different, and the functions may be similar. It is nothing more than configuring the startup environment, but there may also be platform-related factors. I only read run. bat, but I don't know about run. sh. to be cautious, I will only introduce run. bat and will not elaborate on run. sh.

Before introducing the JBoss startup process, I would like to introduce the structural features of JBoss, which will help you understand the startup process. JBoss is based on the JMX framework. Its structure is MBeanSserver and mbeans mounted on MBeanServer. MBean provides the function. MBeanServer is the communication bus between mbeans. The advantage of the JMX framework is that it brings high flexibility and configurability to JBoss. Configurability is also one of the core concepts of JBoss. Almost all JBoss components can be replaced. JBoss helps achieve high configurability through system attributes, configuration files, and other methods. You can customize your own JBoss version by setting system properties or editing the configuration file. This configurability is reflected in every corner of JBoss, and can only be seen during the startup process. If you want to know the whole leopard, you can study other components such as JBoss's EJB container.

After introducing the structural features of JBoss, we start the JBoss startup process. The entire process can be divided into six stages, which will be described in sequence below.

1. Execute the startup script and configure the startup Environment

The JBoss startup process starts from running run. bat. The main task of run. bat is to configure the startup environment.

The JBoss startup environment is actually some startup parameters, such as the JBoss installation path, java command parameters, and JBoss class path.

If an error occurs during the configuration process, the execution of run. bat will be interrupted.

Run. bat will configure the following startup parameters:

JBOSS_HOME

JBoss installation path. The value is C:/JBoss.

PATH

Add C:/JBoss/bin/native to PATH. The files in native are platform-related and can optimize JBoss performance.

JAVA

The path of the java.exe file. Its value is C:/Java/bin/java.

JAVA_OPTSB

Java command parameter, whose value is-Dprogram. name = run. bat-server-Xms128m-Xmx512m-Dsun. rmi. dgc. client. gcInterval = 3600000-Dsun. rmi. dgc. server. gcinteger = 3600000

JBOSS_CLASSPATH

The startup path of JBoss. Its value is C:/Java/lib/tools. jar; C:/JBoss/bin/run. jar. The class files required before JBoss is started are in these two jar files.

If the system environment variable JAVA_HOME is not set, execution of run. bat will be interrupted and JBoss startup will fail. Therefore, after JBoss is installed, you must set

Set the JAVA_HOME system environment variable.

If run. bat runs smoothly, the following command will be executed at the end:

C:/Java/bin/java-Dprogram. name = run. bat-server-Xms128m-Xmx512m-Dsun. rmi. dgc.

Client. gcInterval = 3600000-Dsun. rmi. dgc. client. gcInterval = 3600000-Djava. endorsed. dirs =

C:/JBoss/lib/endorsed-classpath C:/Java/lib/tools. jar; C:/JBoss/bin/run. jar org. jboss. Main/% *

% * Indicates the startup parameter after run. bat.

Run the JBoss code from this command.

Ii. Entry to JBoss startup

JBoss magic begins with the Main. main method. The Main class is located in run. jar. The Main. main method creates a thread group named "jboss", and then creates and runs the thread "main" of the thread group "." Main "after the thread starts running, the Main. main method is executed, and the main thread also ends ." The main thread is mainly used to call the Main. boot Method.

The Main task of the Main. boot method is to process command line parameters and then create and run a server instance. After the server instance starts running, the jboss startup process ends successfully. The following phases are the execution process of the boot method.

3. process command line parameters

The boot method calls the Main. processCommandLine method to process command line parameters. The command line parameter here is actually the args parameter of the main method, which is passed to the processCommandLine method as the real parameter.

The processCommandLine method uses the GNU-getopt package to parse command line parameters. Different methods of processing different command line parameters are described as follows:

After some parameters are processed, the program exits directly. These parameters include:

-H: displays the help message.

-V displays the version information. The version information is obtained from the MANIFEST. MF file in run. jar.

Some parameters are stored in the server properties (Main. props). These parameters include:

-P patch directory.

-N: the url from which the network is started.

-C server configuration name, which is predefined in three types: minimal, default, and all. Of course, it can also be customized.

-Address bound to all the JBoss services of B. This parameter must be configured if you need to access the JBoss service from other machines.

-G HA partition name

-U UDP multicast address

Some parameters are saved in the Main member variables. These parameters include:

-D. The BOOT patch directory is saved in the URL bootURL.

-B: the additional libraries added to the startup class path are saved in List bootLibraries.

-L additional libraries added to the class loading path are saved in List extraLibraries.

-C: the additional url added to the class loading path is saved in List extraClasspath.

Some parameters are saved in system properties. These parameters include:

-D system attributes

-P: Attributes loaded from the specified url

-L specify the log plug-in category. Currently, there are two types: log4j and jdk.

After the processCommandLine method is executed, the boot method loads, creates, and runs a server instance.

4. Load and create server instances

A server instance is a runtime object that represents the running JBoss application server. When a JBoss application server is started, a server instance and

. In JBoss, the implementation of server instances can be configured, that is, the server class can be replaced rather than solidified. This poses a problem:

JBoss must search for and load server classes during startup.

A helper class is used to search for and load server instance classes. Its fully qualified class name is org. jboss. system. server. ServerLoader. This class will be created

A specific class loader, which is used to load server classes, and then a reflection mechanism is used to create a server instance.

The boot method first creates a ServerLoader instance. We call it loader, and then the boot Method adds some URLs to the loader. We call these URLs

Server search path. Loader searches for server classes in the server search path. The server search path includes:

The bootURL is provided by the-d parameter. If the bootURL is a file directory, the jar url under it is also added.

BootLibraries is provided by the-B parameter.

Endorsed jars is located in all jar packages under C:/JBoss/lib/endorsed.

JmxLibs C:/JBoss/lib/The jboss-jmx.jar.

ConcurrentLib C:/JBoss/lib/concurrent. jar.

ExtraLibraries is provided by the-L parameter.

ExtraClasspath is provided by the-C parameter.

Loader comes with url log4j-boot.jar, jboss-common.jar, jboss-system.jar, jboss-xml-binding.jar.

After adding the server search path, the boot method calls the load method of loader. The load method uses the server search path as a parameter, creates a class loader, and uses

It searches for and loads server classes. If the load is successful, we will use the radiation mechanism to create a server instance, which we call a server.

The default server class is org. jboss. system. server. ServerImpl, which is located in C:/JBoss/lib/jboss-system.jar and is not in the jboss class path

. Therefore, the loader must create its own class loader and use the server search path as the class search path to find ServerImpl. Set

Jboss. server. type System attribute. You can also use a custom server class. Of course, the premise is to ensure that the class files of the custom server class need to be searched on the server

Path.

After the server instance is created, you also need to configure it, which is the following initialization work.

V. initialize the server instance

The main task of initializing a server instance is to encapsulate the server configuration information into an object. This object is a class

Org. jboss. system. server. ServerConfigImpl instance. It includes the basic configuration information of the server instance, such as the JBoss installation path and the server root

Directory, server log directory, server temporary directory, server library path, etc.

The boot method calls the init method of the server to start initialization. The Init method delegates the initialization work to the server. doInit method. Create and configure the ServerConfigImpl object using the doInit method, and print the server configuration information in the console and log.

The ServerConfigImpl object is an MBean. Therefore, you can use the jmx console to view the configuration information of the server instance.

After initialization, start the server instance.

6. Start the server instance

Starting a server instance is a complex process, and a lot of work needs to be done. As mentioned above, JBoss is based on the JMX framework, and the main functions of JBoss are as follows:

Provided as a service in the form of MBean, and Services communicate with each other using the JMX bus. So far, we have not seen any JMX-related work. Therefore

During instance startup, the first task is to build a JMX framework. After the JMX framework is built, JBoss needs to create several basic services.

The form of MBean is mounted on the JMX framework. Then, JBoss started the deployment process. JBoss pre-configured services and user deployment units are all deployed and started at this stage.

The boot method calls the server. start method to start the startup process. The start method delegates the startup work to the server. doStart method. The doStart method is followed

Next work:

1. Create and start a timer

This timer is used to calculate the JBoss start time. After JBoss is started successfully, the time consumed during the START process will be output on the console. The secret behind this is here. (This

It doesn't matter. For integrity, let's take a look ).

2. Create an MBeanServer instance

MBeanServer is the core of the JMX framework. JBoss needs to create an MBeanServer instance ., MBeanServer implementation can also be configured. Currently

Two MBeanServer types are used. One is jvm platform MBeanServer, which is provided by the Java platform and the other is provided by JBoss. The fully qualified class is named

Org. jboss. mx. server. MBeanServerImpl. By setting the javax. management. builder. initial System attribute, you can also use custom

MBeanServer. So what kind of implementation does JBoss use? If the Java version reaches or is higher than 5.0, And the jboss. platform. mbeanserver system is

If this parameter is set to true, the jvm platform MBeanServer is used. Otherwise, the MBeanServerImpl provided by JBoss is used. (This is not accurate and involves

LazyMBeanServer, which is not cleared yet. You can think that in most cases, MBeanServerImpl provided by JBoss is used ).

3. Create and register basic services

The following three mbeans are created during MBeanServerImpl creation:

The first MBean is javax. management. MBeanServerDelegate, ObjectName = JMImplementation: type = MBeanServerDelegate

The second MBean is a dynamic MBean, org. jboss. mx. modelmbean. XMBean, ObjectName = JMImplementation: type = MBeanRegistry

The third MBean is org. jboss. mx. loading. UnifiedLoaderRepository3,

ObjectName = JMImplementation: service = LoaderRepository, name = Default

The first MBean was created before MBeanServerImpl was called. The next two mbeans were created by the MBeanServerImpl constructor. The second MBean is used for the MBeanServer registry. All mbeans hanging on the MBeanServer are registered in the registry. The third MBean is related to the JBoss class loading architecture and is also one of the basic services.

Server Server and ServerConfigImpl are both mbeans and also registered to MBeanServer. ObjectName is jboss. system: type = server and jboss. system: type = ServerConfig respectively.

Then, the doStart method creates and registers the following three mbeans:

The first MBean is org. jboss. system. server. ServerInfo,

ObjectName = jboss. system: type = ServerInfo

The second MBean is org. jboss. system. ServiceController,

ObjectName = jboss. system: service = ServiceController

The third MBean is org. jboss. deployment. MainDeployer,

ObjectName = jboss. system: service = MainDeployer

The first MBean mainly encapsulates the information of the software and hardware platform running JBoss, including the host address, J operating system version, and Java version.

The second MBean is used to control the MBean lifecycle. JMX specifications are not specified

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.