Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running two JPA queries in parallel

 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to execute 2 JPA queries in parallel.
Here is the way i am doing it for the moment, from a method inside a class from the business layer :


I am wondering if it makes sense. It works for the moment.
What are the pros and cons ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for whether it makes sense, it depends on what you are trying to solve. Is the query too slow? Have you tried tuning it before adding complexity.

I don't think it is inherently bad to run them in parallel if it is actually necessary. Much of the time, queries are so fast (or could be so fast) that it wouldn't be necessary.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you think you are going to be doing a lot of this kind of concurrent processing, you might want to look at using Akka rather than threads as actors are a heck of a lot easier to manage than threads.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the real reason behind to run two JPA queries in parallel? You should also be cautious when creating your own threads especially when your app is running inside a JEE container. Like Chris mentions in his post above, you would be better off using Akka.
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers.
The reason to run the queries in parallel is to make the web application run faster.
When the user searches for some data, the result is displayed in a new page.
This new page contains the data inside a datagrid (first query) and various sums in the footer (second query).
 
Dave Tolls
Ranch Hand
Posts: 2099
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd look at having the front end request the data then.
One request for the datagrid info and the other for the summary, both of which will be async.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic