Showing posts with label JBoss administration. Show all posts
Showing posts with label JBoss administration. Show all posts

Sunday, 1 September 2013

JBoss AS 7.1.1.Final. EJB Pooling.

This article shows how to stablish the EJB instantiation in JBoss 7.1.1.Final. From a performance point of view, it must be thought how many instances of a stateless bean must be alive at the same time along the application lifecycle.

This article is focused on the standalone JBoss execution mode.

In order to change the maximum number of instances that the application server manage, the following part of the JBOSS_HOME\standalone\configuration\standalone.xml must be changed:

<subsystem xmlns="urn:jboss:domain:ejb3:1.2">

            <session-bean>

                <stateless>

                    <bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>

                </stateless>

                <stateful default-access-timeout="5000" cache-ref="simple"/>

                <singleton default-access-timeout="5000"/>

            </session-bean>

            <pools>

                <bean-instance-pools>

                    <strict-max-pool name="slsb-strict-max-pool" max-pool-size="10" instance-acquisition-timeout="1" instance-acquisition-timeout-unit="MINUTES"/>

                    <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>

                </bean-instance-pools>

            </pools>

      The strict-max-pool tag has two properties:

·         name: Specify the pool of the stateless beans if the value is “slsb-strit-max-pool-size”.

·         max-pool-size specify indeed, the number of max bean instances.

How the application server instantiates the several instances?

It has its own strategy for doing so. That is to say, the bean instances are not created eagerly but they are created by demand, when JBoss considers.

 

Friday, 30 August 2013

JBoss AS 7.1.1.Final Administration. MySQL DataSource creation

Jboss AS 7.1.1 MySQL configuration

This article tries to explain how to create a new DataSource managed by the JEE-container.

The following steps must be followed in order to make available the MySql database system to persist data from beans deployed in the EBJ-Container.

Several steps are needed:

1) Download the MySql jdbc driver. In this case , the version that has been taken into account is the 5.1.26.

2) Add the new DataSource modifying the standalone.xml configuration file located in JBOSS_HOME/standalone/configuration. For doing so, add this elemental datasource element

<datasource jndi-name="java:/PruebaDS" pool-name="PruebaDS">

    <connection-url>jdbc:mysql://localhost:3306/greetingdb</connection-url>

            <driver>mysql</driver>

                    <security>

                        <user-name>root</user-name>

             </security>

 </datasource>

 Elemental explanations : the datasource is accessed by container-managed beans or external clients via JNDI. His name is “java:/PruebaDS”.

<connection-url> : It is the connection string needed if you want mysql to be your persistence database system. In this case, my database is called “greetingdb”.

<driver>: it refers to the .jar file that is installed as a JBOSS module (see later).

<security>: It specify the user of the database.

As well, the driver reference must be reflected in the previous file. 

<driver name="mysql" module="com.mysql"/>

The whole section of the file defining this new datasource is the following:

<subsystem xmlns="urn:jboss:domain:datasources:1.0">

            <datasources>

                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">

                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>

                    <driver>h2</driver>

                    <security>

                        <user-name>sa</user-name>

                        <password>sa</password>

                    </security>

                </datasource>

                <datasource jndi-name="java:/PruebaDS" pool-name="PruebaDS">

                    <connection-url>jdbc:mysql://localhost:3306/greetingdb</connection-url>

                    <driver>mysql</driver>

                    <security>

                        <user-name>root</user-name>

                    </security>

                </datasource>

                <drivers>

                    <driver name="h2" module="com.h2database.h2">

                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>

                    </driver>

                    <driver name="mysql" module="com.mysql"/>

                </drivers>

            </datasources>

        </subsystem>

 

You can see two datasource defined with their respective drivers.

3) Now, it is the moment to install the new module in the JBOSS Application Server. It is quite simple. The steps are the following:

·         In the JBOSS_HOME/modules create the file structure /com/mysql/main (JBOSS_HOME/modules/com/mysql/main/

·         In this directory, copy the jar previously downloaded.

·         Create a file called module.xml and insert the following content:

<module xmlns="urn:jboss:module:1.0" name="com.mysql">

   <resources>

     <resource-root path="mysql-connector-java-5.1.26-bin.jar"/>

   </resources>

   <dependencies>

      <module name="javax.api"/>

      <module name="javax.transaction.api"/>

    </dependencies>

</module>

This file refers the jar file and the dependencies needed to make it available.

4) Start the JBOSS server and check if the datasource is well deployed:

 

13:44:20,984 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:/PruebaDS]

Some like this you might find in the logging trace of the server once it is run.