aspose file tools*
The moose likes Performance and the fly likes Fast querie but return is to slow, Odd behavior? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Fast querie but return is to slow, Odd behavior?" Watch "Fast querie but return is to slow, Odd behavior?" New topic
Author

Fast querie but return is to slow, Odd behavior?

Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
Hello i was wondering about this odd behavior,
i have this jpa (Eclipselink) Query


the line listaMyObject = query.getResultList(); doesnt take more thatn 400ms while the return statment takes about 4000ms and im only returning like 50 elements,
is it because the object is to heavy?, what am i missing? any ideas would be helpfull thanks!


Asterisk-java, JSF, Primefaces, JEE & Glassfish.

Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2333
    
  28

No it's not the return. Returning just returns a reference to the list. It's not copying the contents of the list.

Does your method have annotations? Probably there is some code woven into your code that is taking time. Maybe JPA is flushing some other changes you have done in the transaction? Take a thread dump when you encounter the "freeze". Or, debug the code, and when it's frozen, hit pause button. It should tell you what exactly it;s doing when it freezes.
Luan Cestari
Ranch Hand

Joined: Feb 07, 2010
Posts: 162

What Jayesh said is right, this issue might be because some behavior from the container due some annotation (like maybe after that method it resumed a pending transaction or sth like that)


Please, visit me for some cool tech post at www.ourdailycodes.com
Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
the only annotation present in the method is the @Override right above it. But great idea im gonna debug and pause and see whats going
Luan Cestari
Ranch Hand

Joined: Feb 07, 2010
Posts: 162

Paul Monique wrote:the only annotation present in the method is the @Override right above it. But great idea im gonna debug and pause and see whats going


But does the class have any annotation or XML referencing that class? Which framework stack are you using?
Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
the class has the @Stateless annotation, im running jee ejb, with primefaces on netbeans
Ran the debug but couldnt find anything, gonna try the profiler but i dont know much about it
Luan Cestari
Ranch Hand

Joined: Feb 07, 2010
Posts: 162

@Stateless, so you use EJB. DO you have any transaction annotation (the default is required, but I'm worried if you suspend it)

How did you measure this -> " the return statment takes about 4000ms" ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41532
    
  53
How (or where) are you measuring this? In other words, what do the 4000ms include?


Ping & DNS - my free Android networking tools app
Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
Ulf Dittmer wrote:How (or where) are you measuring this? In other words, what do the 4000ms include?


i setup something like this inside the code

and also inside the facade that is excuting the query



so i get the during the excution query time and after the return
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41532
    
  53
I see, so there's nothing much else going on that might be included in the higher number.
Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
Yes! thats why im wondering about that odd behaviour
Luan Cestari
Ranch Hand

Joined: Feb 07, 2010
Posts: 162

I think the Glassfish is pushing that whole object to the transaction (whatever reason). Try to change the beans used by those tests to be all @Stateless (no @Stateful) and all using @TransactionAttribute(TransactionAttributeType.NEVER) in the top of the class (and also guarantee there is no other @TransactionAttribute in use than this one). This will make very stateless and no transaction. Check if there is any difference after this change.

I also notice that the snippet have a type (or maybe is related to this issue) there is "listaMyObject" and also there is "listMyObject" in the code. is that right (like it compiles and you have an instance variable )?
Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
Sorry for the late reply, after adding @TransactionAttribute(TransactionAttributeType.NEVER), im getting the exception javax.ejb.EJBException: EJB cannot be invoked in global transaction , i google but couldnt find a precise answer, im gonna go trough all the transactions im doing during the loading page process, thanks a lot!


pd: the snippet is a misstype error i did while posting sorry
Luan Cestari
Ranch Hand

Joined: Feb 07, 2010
Posts: 162

Paul Monique wrote:Sorry for the late reply, after adding @TransactionAttribute(TransactionAttributeType.NEVER), im getting the exception javax.ejb.EJBException: EJB cannot be invoked in global transaction , i google but couldnt find a precise answer, im gonna go trough all the transactions im doing during the loading page process, thanks a lot!


pd: the snippet is a misstype error i did while posting sorry


Nice. If the page is only loading stuff from DB, it shouldn't need transaction at all (it only make sense for INSERT/UPDATE). So putting this will also increase the performance (you may just need to set the right attribute for each situation, like if you have to insert sth, you can use SUPPORTS in some beans and in the exactly the bean that make the INSERT you can start the transaction (using REQUIRED), just for a example ).

For more info:
http://openejb.apache.org/transaction-annotations.html
http://docs.oracle.com/javaee/6/api/javax/ejb/TransactionAttributeType.html
Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
Wow thanks for the input. I didn't know the importance of TransactionAttribute annotation. I'm going to check out those links, THANKS again for all the help!!


pd: Is gonna put a whole new meaning on my transactions
 
 
subject: Fast querie but return is to slow, Odd behavior?