JBoss Startup loading process detailed (-)

Source: Internet
Author: User
Tags jboss jboss application server log4j

Today I looked at JBoss Boot.log and Server.log logs, combined with their own understanding and other information, and now the launch and loading process of JBoss to make the following summary;

This article takes the 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 narrative, the following assumptions are made to the platform environment: the installation path for the Java runtime is C:/java,jboss C:/jboss.

since JBoss, written in 100% Java, has cross-platform features, why stress the Windows platform. This is because JBoss startup starts with a platform-dependent script file, and the script files on different platforms are different. For example, the script file on the window platform is the script on the Run.bat,linux platform is run.sh. The contents of the two files are very different, the function may be similar, nothing more than the configuration of the boot environment, but there may be platform-related factors. I only looked at the Run.bat, run.sh do not understand, for the sake of prudence, I only introduce run.bat, run.sh do not elaborate.

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, and its structure is a mbeansserver and some mbean that hangs on the mbeanserver. The Mbean provides functionality, and the mbeanserver is the communication bus between the Mbean. The advantage of the JMX framework is that it provides JBoss with a high degree of flexibility and configuration. The ability to configure is one of the core concepts of JBoss, and almost all jboss components can be replaced. JBoss helps to achieve a high degree of flexibility through a variety of methods, such as System properties, configuration files, and more. We can customize our version of JBoss by setting the system properties or by editing the configuration file. This configuration is reflected in all areas of JBoss, and the start-up process can only be seen, and if you want to know whole picture, consider other components such as JBoss EJB container.

after introducing the structural features of JBoss, we started to get into the JBoss startup process. The entire process can be divided into six stages, which are described in turn.

      

First, execute the startup script, configure the startup environment

The start- up process for JBoss begins with the execution of Run.bat, and Run.bat's primary task is to configure the boot environment.

JBoss Startup environment is actually some startup parameters, such as the installation path of JBoss, Java command parameters, JBoss Classpath, and so on.

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

Run.bat will configure the following startup parameters:

Jboss_home

JBoss installation path with a value of C:/jboss

PATH

adding c:/jboss/bin/native to Path, the files under native are platform-dependent and can optimize the performance of JBoss.

JAVA

the path to the Java.exe file whose value is C:/java/bin/java

JAVA_OPTSB

The parameters of the Java command, whose value is-dprogram.name=run.bat–server-xms128m–xmx512m–dsun.rmi.dgc.client.gcinterval=3600000– dsun.rmi.dgc.server.gcinterval=3600000

Jboss_classpath

the starting classpath for JBoss, with a value of C:/java/lib/tools.jar; C:/jboss/bin/run.jar. The class files required for JBoss start-up are in these two jars.

if the system environment variable java_home is not set, then the execution of the Run.bat will be interrupted and the JBoss boot fails. Therefore, after installing JBoss, be sure to set the

java_home system Environment variables.

if Run.bat performs well, 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/%*

the%* represents the startup parameters behind the Run.bat.

start with this command and actually run JBoss's code.

 

ii. access to JBoss startup

JBoss Magic begins with the Main.main method. Main This 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. After the "main" thread starts running, the Main.main method executes and the main thread ends. The main task of the "main" thread is to call the Main.boot method.

The main task of the Main.boot method is to process command-line arguments and then create and run a server instance. When the server instance starts running, the JBoss startup process is completed successfully. The following phases are the process of the boot method execution.

 

third, processing command line parameters

The boot method calls the Main.processcommandline method to handle command-line arguments. The command-line argument here is actually the args parameter of the main method, which is passed to the ProcessCommandLine method as an argument.

The ProcessCommandLine method uses the Gnu-getopt package to parse the command-line arguments, with different processing methods for different command-line arguments, briefly summarizing the following:

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

-H Displays the help message.

-V Displays version information. The version information is obtained from the MANIFEST.MF file in Run.jar.

some of the parameters are saved in the server properties (Main.props), which include:

-P Patch directory.

-n The URL that is launched from the network.

The name of the- C server configuration, predefined three kinds, minimal, default, and all. Of course, you can customize it.

- b The address of all JBoss service bindings, which you must configure if you need to access the JBoss service from another machine.

the name of the-G ha partition

-u UDP multicast address

some of the parameters are stored in the member variable of Main, which includes:

- d boot patch directory saved in URL Booturl

- B Additional libraries added to the startup Classpath are saved in the list bootlibraries

- L Additional libraries added to the class load path are saved in the list extralibraries

- C Additional URLs added to the class load path are saved in the list Extraclasspath

some of the parameters are saved in the System properties, which include:

- D System Properties

-p properties loaded from the given URL

-l Specifies log plug-in class, currently has log4j and JDK two kinds.

when the ProcessCommandLine method finishes executing, the boot method loads, creates, and runs a server instance.

 

Iv. loading and creating a server instance

 

A server instance is a run-time object that represents a running JBoss application server. Starting a JBoss application server, you will have a server instance with

the corresponding. In JBoss, the implementation of the server instance can be configured, that is, the server class is not cured, but can be replaced. This poses a problem:

JBoss must search for and load the server class during startup.

the task of searching for and loading a server instance class is done by an auxiliary class whose fully qualified class name is Org.jboss.system.server.ServerLoader. This class will create

a specific ClassLoader and uses the ClassLoader to load the server class, and then use the reflection mechanism to create a server instance.

The boot method first creates a ServerLoader instance, which we call loader, and then the boot method adds some URLs to the loader. We refer to these URLs as

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

the Booturl is provided by the-D parameter. If Booturl is a file directory, the URL of the jar beneath it is also added.

the bootlibraries is provided by the-B parameter.

endorsed jars all jar packages located under C:/jboss/lib/endorsed.

jmxlibs C:/jboss/lib/jboss-jmx.jar.

concurrentlib C:/jboss/lib/concurrent.jar.

the extralibraries is provided by the-l parameter.

the Extraclasspath is provided by the-C parameter.

loader comes with URLs Log4j-boot.jar, Jboss-common.jar, Jboss-system.jar, Jboss-xml-binding.jar.

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

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

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

the. Therefore, loader must create its own classloader and use the server search path as the class search path to find Serverimpl. By setting

Jboss.server.type System Properties, you can also use custom server classes. Of course, the premise is to ensure that the class file of the custom server class is searched on the server path

the path.

after the server instance has been created, it needs to be configured, which is the following initialization work.

 

v. Initializing the server instance

 

the primary task of initializing a server instance is to encapsulate the server configuration information in an object. This object is a class

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

directory, the server's log directory, the server's temp directory, the server's library path, and so on.

the boot method invokes the Init method of the server and begins the initialization work. The Init method delegates the initialization work to the server: Doinit method. The Doinit method creates and configures the Serverconfigimpl object, and finally prints out the server's configuration information in the console and in the log.

The Serverconfigimpl object is an Mbean, so users can use the JMX console to view configuration information for a server instance.

Once the initialization is complete, the server instance is started.

 

Vi. Starting the server instance

     

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

in the form of an mbean as a service, the service communicates with the JMX bus. So far, we haven't seen JMX-related work. Therefore, in the service

The first step in the startup process of the instance is to build the JMX framework. After the JMX framework is built, JBoss needs to create several basic services that are

the form of an mbean, which hangs on the jmx frame. After that, JBoss begins the deployment process. JBoss preconfigured services, the user's deployment unit, are deployed and started at this stage.

the boot method invokes the Server.start method and begins the startup process. The Start method delegates the startup work to the Server.dostart method. The Dostart method is completed sequentially to

work under:

1. Create and start a timer

This timer is used to calculate the time of JBoss startup, and the secret behind this is the time it takes for the console to output the startup process after the JBoss boot succeeds. (This

It doesn't matter, for completeness to introduce).

2. Create a Mbeanserver instance

Mbeanserver is the core of the JMX framework. JBoss needs to create a Mbeanserver instance. , the implementation of Mbeanserver can also be configured. can now

using two kinds of mbeanserver, one is the JVM platform Mbeanserver, it is provided by the Java platform, and the other is provided by JBoss, the fully qualified class name is

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

Mbeanserver. So what kind of implementation is jboss using? If the Java version reaches or exceeds 5.0, and the Jboss.platform.mbeanserver system belongs to

true, use the JVM platform Mbeanserver, or use the Mbeanserverimpl provided by JBoss. (this point is inaccurate and involves

Lazymbeanserver, I'm not quite clear yet. As you can see, most of the cases are Mbeanserverimpl provided by JBoss.

 

3. Create and register a basic service

 

During the creation of the Mbeanserverimpl, the following 3 Mbean are created:

        

the first Mbean is Javax.management.MBeanServerDelegate, objectname=jmimplementation:type=mbeanserverdelegate< /c6>

The second mbean is a dynamic mbean,org.jboss.mx.modelmbean.xmbean,objectname=jmimplementation:type=mbeanregistry

The third Mbean is a org.jboss.mx.loading.UnifiedLoaderRepository3,

objectname=jmimplementation:service=loaderrepository, Name=default

 

The first Mbean was created before the call to Mbeanserverimpl, followed by the two Mbean that were created in the Mbeanserverimpl constructor. The second Mbean is the registry used to Mbeanserver, and all Mbean that hangs on Mbeanserver are registered in the registry. The third Mbean is related to the class-loading architecture of JBoss and is one of the basic services.

 

Server server and Serverconfigimpl are also Mbean, and are also registered to Mbeanserver,objectname Jboss.system:type=server and Jboss.system respectively: Type=serverconfig.

The Dostart method then creates and registers the following 3 Mbean:

The first Mbean is a org.jboss.system.server.ServerInfo,

objectname= Jboss.system:type=serverinfo

The second Mbean is a org.jboss.system.ServiceController,

objectname= Jboss.system:service=servicecontroller

The third Mbean is a org.jboss.deployment.MainDeployer,

objectname= Jboss.system:service=maindeployer

The first Mbean mainly encapsulates information about the hardware and software platforms that JBoss runs, including host addresses, J-OS versions, Java versions, and so on.

The second mbean is used to control the life cycle of the Mbean. The JMX specification does not provide

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.