Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance MDB

 
Robert Siqueira
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My system have been using JPA + EJB3 + Mysql.

I have an EJB which send a message to a jboss queue.

Inside my MDB, I have a loop of 5000 cycles.

Inside this cycle I do a SELECT in my database to return a count(*).

The problem is, after aprox. 4000 cycles, I get the exception Closed connection by Hibernate.

The problem could be my mysql ? Jboss and Mysql are in the same machine. Its a desktop, with 3GB, duo core, win 7.

Regards,

Robert
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post some code that performs the cycles ?
 
Robert Siqueira
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote:Could you post some code that performs the cycles ?



follow.. I think the problem could be my architecture.

As you can see, I have a DaoFactory which return my DAO classes.

Could you please give me your assumptions ?

The steps are: MDB -> GestorCobranca -> DAOFactory -> DAO.


Regards,

Robert



 
Robert Siqueira
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this the Exception Im getting:

 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced a similar issue once with my MDBs. However, the exception there was different.
The issue was that normally MDBs running inside transactions will have the normal default transaction timeout configured. So, my code implemented inside the MDB was not getting executed inside the default time and hence the transaction was getting aborted while the code is running.
At the end when the code completes and the tx tries to commit, it was throwing an error saying some thing like trying to commit an already aborted transaction. It became very tricky to realize that the timeout was the issue.
You can check if you are also running into a similar issue.
 
Robert Siqueira
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lokesh chenta wrote:I faced a similar issue once with my MDBs. However, the exception there was different.
The issue was that normally MDBs running inside transactions will have the normal default transaction timeout configured. So, my code implemented inside the MDB was not getting executed inside the default time and hence the transaction was getting aborted while the code is running.
At the end when the code completes and the tx tries to commit, it was throwing an error saying some thing like trying to commit an already aborted transaction. It became very tricky to realize that the timeout was the issue.
You can check if you are also running into a similar issue.



thks for the answer..
I was looking into my logs, and I saw something about timeout. I think you could be right. Could be the timeout. Do you know what I could do in that case ? There is some approach to disable the timeout or something like that ?

Regards,

Robert




 
Robert Siqueira
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks lokesh chenta.. You saved my life !

you were right. My MDB was in a transaction and because that i had the timeout because the process takes a long time.

I put a @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) in my MDB and now everything is fine.

thanks a lot guy

Reagards,

Robert
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Robert,
Great to hear that it was the same issue and my info has helped
Right now, you have disabled tx for the MDB using @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED).
And in case if you want to use tx for this MDB in future and if you are not aware, you can increase the timeout also using annotations( atleast available in jboss as @TransactionTimeout(900) ).
And just an additional suggestion, if possible, you can have a relook at your code as well and see if you can optimize it so that it completes quickly as well.
All the Best
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A small suggestion for code optimization, instead of looping the collection in the MDB, you could pass the same collection to a DAO method that takes a collection as an argument.
This means that you will make single service call, single DAO call & same entity manager will be used to persist the collection.
This will save multiple lookups for DAO & Entity Manager. These lookups have a performance overhead.
You could make the code changes & check if it improves performance. In my opinion you should see improvements.
 
Robert Siqueira
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put the @TransactionTimeout(5000) in my EJB (stateless) in method scope. But, the timeout continues with aprox. 1 minute. Is there a maximum value to the timeout ?

Regards,

Robert
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought you said that disabling txs on MDB with the annotation has solved your problem..
Is it that you have disabled tx on MDB but using it in the EJBs? If yes, I do not see anything inside the posted stateless bean code that can take lot of time and cause a time. Only issue in such scenario would be that for each iteration inside the MDB, you will be starting a new tx for the bean.
And, as far as i know, there is no limit on the timeout that can be specified and the 5000 mins should have taken effect. Not sure what's going wrong and why it is timing out in 1min. You might have to do some more debugging. Worst case, you can try attaching a profiler and watch the threads.
 
Robert Siqueira
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget my last post.... everything is ok !!! Was my mistake !

Thks a lot..

Robert
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic