Reputation: 1823
Scenario: In any kind of online Reservation application there is possiblty that people may acesses the application at the same time. Because of this there could be a concurrency issues in that perticular application.
Problem:
In this case, if one or more people accessing the application at a time then there is a problem of concurrency issue.
To solve concurrency the issue we have two solutions
1) Java Concurrency at Client level
2) JPA Optimistc or Pessimistic Locking at persistence level
If the database contains 10 millions or more records then which one is the optimal solution?
Upvotes: 0
Views: 3229
Reputation: 1823
It completely depends on the application. If the Datamodel, not complex and not huge then the JPA Optimistic Locking is an optimal solution.
Both Java & Database Concurrency have there own advantages and disadvantages.
Database level:
Advantage:
1) its easier to implement and also for maintenance.
Disadvantage:
1)If the database contains huge and complex data then it may causes deadlocks and timeouts.
Java Level:
Advantages:
1) Better resource Utilization
Disadvantages:
1) Debugging & Testing very complex.
2) There is a possibility deadlock occurence.
3) Difficult to implement in Java Programming.
4) An Element of risk involved with a bad design.(Starvation)
5) it's not portable from one environment to another environment
ref: java Concurrency vs JPA concurrency
Upvotes: 0
Reputation: 3702
Performance issues and Concurrency issues are two different problem domains altogether. Its better not to mix both.
Regarding concurrency issues: Java Concurrency or Multi threading may be of very limited use in a online reservation system. To avoid problem of lost updates, you must use either JPA Optimistic Locking (preferably) or Pessimistic Locking. That's because if multiple instances of your application are running in parallel (or multiple threads) then its impossible to avoid lost updates using JVM level thread-safety techniques.
You can refer to the below tutorials:
Upvotes: 1