GeeCON Prague 2014*
The moose likes Performance and the fly likes Performance MDB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Performance
Bookmark "Performance MDB" Watch "Performance MDB" New topic
Author

Performance MDB

Robert Siqueira
Ranch Hand

Joined: Jan 21, 2008
Posts: 37
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

Joined: Feb 24, 2006
Posts: 6661
    
    5

Could you post some code that performs the cycles ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Robert Siqueira
Ranch Hand

Joined: Jan 21, 2008
Posts: 37
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

Joined: Jan 21, 2008
Posts: 37
this the Exception Im getting:

lokesh sree
Ranch Hand

Joined: Oct 27, 2009
Posts: 100

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.


Lokesh
( SCBCD 5, CCENT, SCJP 5 )
Robert Siqueira
Ranch Hand

Joined: Jan 21, 2008
Posts: 37
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

Joined: Jan 21, 2008
Posts: 37
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

Joined: Oct 27, 2009
Posts: 100

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

Joined: Aug 11, 2010
Posts: 218

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

Joined: Jan 21, 2008
Posts: 37
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

Joined: Oct 27, 2009
Posts: 100

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

Joined: Jan 21, 2008
Posts: 37
Forget my last post.... everything is ok !!! Was my mistake !

Thks a lot..

Robert
 
GeeCON Prague 2014
 
subject: Performance MDB