• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Running two JPA queries in parallel

 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE 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 ?
 
author & internet detective
Posts: 40200
816
Eclipse IDE VI Editor Java
  • 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.
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • 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.
 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE 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: 563
Google Web Toolkit Eclipse IDE 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).
 
Master Rancher
Posts: 4668
49
  • 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.
 
I don't like that guy. The tiny ad agrees with me.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic