• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running two JPA queries in parallel

 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic