Wednesday, October 03, 2012

Why C3P0 over Commons DBCP?

What is Connection pool?
Connection pool is good for performance, as it prevents Java application create a connection each time when interact with database and minimizes the cost of opening and closing connections. The purpose is to reuse the connections and manage the process of opening, closing efficiently.

The shortcomings/disadvantages of Commons DBCP are very clearly documented over Tomcat 7.0 JDBC connection pool  documentation.

  1. commons-dbcp is single threaded, in order to be thread safe commons-dbcp locks the entire pool, even during query validation.
  2. commons-dbcp is slow - as the number of logical CPUs grow, the performance suffers, the above point shows that there is not support for high concurrency Even with the enormous optimizations of the synchronized statement in Java 6, commons-dbcp still suffers in speed and concurrency.
  3. commons-dbcp is complex, over 60 classes. tomcat-jdbc-pool, core is 8 classes, hence modifications for future requirement will require much less changes. This is all you need to run the connection pool itself, the rest is gravy.
  4. commons-dbcp uses static interfaces. This means you can't compile it with JDK 1.6, or if you run on JDK 1.6/1.7 you will get NoSuchMethodException for all the methods not implemented, even if the driver supports it.
  5. The commons-dbcp has become fairly stagnant. Sparse updates, releases, and new feature support.
  6. It's not worth rewriting over 60 classes, when something as a connection pool can be accomplished with as a much simpler implementation.
  7. Tomcat jdbc pool implements a fairness option not available in commons-dbcp and still performs faster than commons-dbcp
  8. Tomcat jdbc pool implements the ability retrieve a connection asynchronously, without adding additional threads to the library itself
  9. Tomcat jdbc pool is a Tomcat module, it depends on Tomcat JULI, a simplified logging framework used in Tomcat.
  10. Retrieve the underlying connection using the javax.sql.PooledConnection interface.
  11. Starvation proof. If a pool is empty, and threads are waiting for a connection, when a connection is returned, the pool will awake the correct thread waiting. Most pools will simply starve.


See my other post (Tomcat 7: C3P0 Datasource Pool) summarizing how to Configure C3P0 in Tomcat 7.

Tomcat 7: C3P0 Datasource Pool

Goal:

To configure C3P0 datasource pool in tomcat 7

Detail: 

Till now I was using DBCP JDBC connection pooling for my applications. Considering that the library seems to be out of date now and is not meant for production grade system with heavy load on them, I looked towards the other free open source connection pooling library C3P0.

C3P0 is an easy-to-use library for making traditional JDBC drivers "enterprise-ready" by augmenting them with functionality defined by the jdbc3 spec and the optional extensions to jdbc2.
Below are the steps to configure C3P0 pool in tomcat. 
  1. Download the latest c3p0-{version}.jar from http://sourceforge.net/projects/c3p0/.
  2. Copy the c3p0-{version}.jar to tomcat/lib directory.
  3. Open the tomcat/conf/context.xml in edit mode and add the below lines inside <Context> element.
    <Resource auth="Container" description="DB Connection" driverClass="com.mysql.jdbc.Driver" maxPoolSize="50" minPoolSize="10" acquireIncrement="10" name="jdbc/MyDBPool" user="root" password="abc123" factory="org.apache.naming.factory.BeanFactory" type="com.mchange.v2.c3p0.ComboPooledDataSource" jdbcUrl="jdbc:mysql://localhost:3306/lportal?autoReconnect=true" />
     
  4.  For  more on configuring various attributes of the connection pool, see http://www.mchange.com/projects/c3p0/#configuration

Environment:

Java 6
Tomcat 7
MySQL 5

Reference:

See my other post (Why C3P0 over Commons DBCP?) for more on DBCP vs C3P0 

Monday, October 01, 2012

Liferay 6.1: Documents And Media CMIS: Install & Configure Xuggler

Goal: 


Installation and Setup:

  • Install Xuggler 3.4 from http://www.xuggle.com/xuggler/downloads/
  • Configure Xuggler environment variables in setenv.sh
    export XUGGLE_HOME=/usr/local/xuggler
    export LD_LIBRARY_PATH=$XUGGLE_HOME/lib:$LD_LIBRARY_PATH
    export PATH=$XUGGLE_HOME/bin:$PATH
  • Start the tomcat
  • Go to Control Panel -> Server Administration->External Services. Select the version of Xuggler binary library compatible with your environment and follow the instructions.
  • You will need to restart the tomcat after above step as per the installation process.
  • To Enable Xuggler in portal
    Control Panel -> Server Administration->External Services -> Enable Xuggler
  • Now you are ready to play audio/video files uploaded in Documents And Media portlet.

Environment:

  • Linux 64 bit (libc version 6)
  • Liferay 6.1 GA2
  •  Tomcat 7
  • Java 1.6.0.20

Reference :

Friday, September 28, 2012

Liferay 6.1: Documents And Media CMIS: Integrating External Repository

Adding repositories in Documents and Media portlet is a new. Documents and Media allows to connect to multiple third-party repositories that support CMIS 1.0 via AtomPUB or Web Services protocols.
To add new repositories from the web click the Add button from the Home folder. Repositories can only be mounted in the Home folder.
Need to make sure that same credentials are being used  in liferay and external repository for authentications. In order to authenticate and make it working you need to enable the following in portal.properties.
session.store.password=false
company.security.auth.type=screenName

Example 

  1. External Repository is Alfresco 4.
  2. Once the  Liferay and Alfresco are up and working either both on same tomcat or separate (i have deployed on same tomcat).
  3. Goto Document and Media portlet >> Click on Add >> select "Repository"
  4. Enter Name, Description.
  5. Select type as Atompub.
  6. For AtomPub URL enter "http://localhost:8080/alfresco/service/cmis" and click Save.
  7. You will see a new entry on left side and now you will be able to browse and search the Alfresco repository.

Environment:

References:

    • User guide of http://www.liferay.com
    • http://www.liferay.com/es/community/wiki/-/wiki/Main/CMIS+Repository#section-CMIS+Repository-Mounting+a+Repository

Thursday, September 27, 2012

Organizations or Communities, which one should I use?

The concept of Organization, Community, groups have been extended in Liferay 6.1, providing a greater flexibility and customization. Below is the link from Liferay official site which explains this in a simple yet practical manner.
Organizations or Communities, which one should I use? The final answer