How to use GlassFish’s Connection Pool in Jelastic

GlassFish provides its Connection Pooling mechanism for resources such as EIS Server, JMS Server and Database Server. How can it help you?

Connection Pooling is intended to share server resources among requesting clients. Creating a new connection for each request can take a lot of time, but pooling connections fixes this drawback by eliminating the multiple, individual requests. When a user makes a request, a connection from the pool is directed and when he or she is finished with the connection, it is returned to the pool, making it available for any consequent requests. Connection Pooling decreases the response time for the application to get, use and close connections, as the actual connections to the data store are managed by the pool.

Let’s check out how to setup GlassFish’s Connection Pool in Jelastic!

1. Create an environment

  1. Go to Jelastic.com and sign up if you haven’t done so yet or log in with your Jelastic credentials by clicking the Sign In link on the page.
  2. Within the Jelastic dashboard, click the Create environment button:
  3. glassfish connection pool

  4. In the Environment Topology dialog, pick GlassFish as your application server and the database you want to use (for example MySQL). Increase your limit to 12 cloudlets. Then type your environment name–for example, testCP.

glassfish pool
It will take just a minute for your environment to be created.

glassfish's connection pool

2. Configure database

  1. Click the Open in browser button for MySQL.
  2. pool connection for glassfish

  3. When you created the environment, Jelastic sent you an email with credentials to the database. Use these credentials to create a user account and the database with the application.

glassfish database connection

glassfish db connection

3. Connection Pool configuration

  1. Upload the MySQL connector to the lib folder and restart GlassFish.
  2. jdbc connection pool

  3. Open the GlassFish admin page in a web browser.
  4. jdbc

  5. Sign in with the login and password which Jelastic sent to your email.
  6. Create a new JDBC Connection Pool. At the first step, type pool name, choose resource type (javax.sql.DataSource), database driver vendor (MySQL) and click on the Next button.
  7. connection pool

  8. Then set the connection to your database: type the port number, your database name, database URL, user name and password. Then click Finish.
  9. glassfish db config
    As you can see the Connection Pool is successfully created.
    establish glassfish pool

  10. Create a new JDBC Resource: type JNDI name, choose pool name and select target (gfcluster).

jdbc pool

4. Getting a connection from your Java code

Put the following code into your Java class:

InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(“jdbc/testcp”);
Connection conn = ds.getConnection();

Now you can deploy your application to Jelastic Cloud and enjoy!

4 Responses to “How to use GlassFish’s Connection Pool in Jelastic”

  1. Newsletter – March 15, 2012 « Jelastic — Rock-Solid Java in the Cloud, Java Server Hosting, Java Cloud Computing

    [...] If you are interested in reading a little more about the Connection Pooling mechanism and how to make it work for you within Jelastic, you can read the how-to. [...]

    Reply
  2. Tab Sweep – Java EE wins, Prime Faces JSF, NetBeans, Jelastic for GlassFish, BeanValidation, Ewok and more… « oracle fusion identity

    [...] Components in JSF 2.0 (Mr. Bool) • Key to the Java EE 6 Platform: NetBeans IDE 7.1.x (OTN) • How to use GlassFish’s Connection Pool in Jelastic (jelastic.com) • Bean Validation 1.1 early draft 1 is out – time for feedback (Emmanuel) [...]

    Reply
  3. Latest-Tutorial » Spring Batch Example » Latest-Tutorial

    [...] How to use GlassFish’s Connection Pool in Jelastic (jelastic.com) [...]

    Reply
  4. Server Monitoring « Eternal Traveller and the Mysterious Sojourner !

    [...] How to use GlassFish’s Connection Pool in Jelastic (jelastic.com) [...]

    Reply

Leave a Reply