I have a MDB that receives data from a JSM queue in XML format. After converting the XML to proper Value Objects using JAXB, it calls a DAO.
We have configure the App server (WLS 8.1)to have 10 MDB in the pool.
The DAO is a singleton with a none static private data member that holds the DataSource.
The DAO.add() operation gets connection from the data source and performs the add.
When we put one msg on the JMS queue we see the transaction time in DAO.add() is an about 1 sec.
When we put 30 msgs on the JMS queue we see 10 threads accessing the singleton instance of the DAO.
I was hoping to see the DB transactions started by these 10 threads would be executed in parallel they way threaded operations should behave considering the context switching factor however what I am seeing from the log files is that the DB transactions are serialized meaning they get executed one at a time!!?? Therefore it takes 10 sec for the 10 threads to complete their work. I was expecting to see something like 3 to 4 sec for all 10 thread to complete the add operation.
Anyone has any ideas? Could it be that the Datasource is a private member of the Singleton DAO and each thread who calls the DAO.add() gets queued up to get access to the Data Source?
Any idea would be great.
Here a suggestion: normally the singleton pattern is implemented by serializing calls to the singleton's getInstance() with the synchronized() keyword. Could it be that your ten threads are serialized when calling dao.getInstance()? Of course subsequently they are free to operate in parallel, but what actions are happening in the constructor? Perhaps it is slowing down the whole operaton.
What is the benefit of implementing DAOs as singletons?
Alternatively, perhaps you are calling a synchronized method elsewhere. For example, a lot of methods on OracleDatasource are synchronized.
<What is the benefit of implementing DAOs as singletons?
Alternatively, perhaps you are calling a synchronized method elsewhere. For example, a lot of methods on OracleDatasource are synchronized.>>
The Singleton's getInstance() is not mandated to be synchronized merely due to the nature of Singleton that should be Stateless/Read only object. Therefore our DAO.getInstance() is notsynchronized. In the private constructor however obtains a reference to the Weblogic DataSource and store it in a private data member and again this happens once for the life cycle of the object. Unless the JVM sychronizes the access to this private data member I can't see if the Singleton is the cause of the problem. Do you know if Weblogic sychronizes the multiple calls to the data source?