I have three instances of same application running in different JVMs. I don't want a specific value in the data base to modified by different applications at the same time. How do I enforce this restriction in java?
Asked
Active
Viewed 2,046 times
1

Anthon
- 69,918
- 32
- 186
- 246

Bhargav Kumar R
- 2,190
- 3
- 22
- 38
-
Did you try to use a transaction manager ? – Viraj Mar 23 '15 at 06:14
-
2The RDBMS engine already guarantees that for you. Therefore there is no problem. Or you don't tell the full story. – fge Mar 23 '15 at 06:15
-
no distractions, no chit-chat (read [help→tour](http://stackoverflow.com/tour)), thanks are never part of a good question. – Anthon Mar 23 '15 at 06:32
-
Data base is oracle.. I did not try using transaction manager.. – Bhargav Kumar R Mar 23 '15 at 06:58
1 Answers
2
It depends on the technology stack you are using.
- You may want to consider to do Optimistic or Pessimistic Concurrency Control
- If you need pessimistic concurrency control, and if you are using JDBC directly, it will be DBMS-specific for the way to do row lock (some DBMS may not even allow you to do so). For example, in Oracle, you do it by
select * from table_name for update
- If you are using JPA or Hibernate, it is wrapped by
EntityManager.lock(entity)
/Session.lock(entity)
(something similar) - In some case you don't even need to do anything special.
Unless you provide more details of your problem, it's very difficult to give you a concrete suggestion.

arshovon
- 13,270
- 9
- 51
- 69

Adrian Shum
- 38,812
- 10
- 83
- 131
-
Thanks for the response. My data base is oracle and i am doing it using JDBC. can you explain a bit more.. – Bhargav Kumar R Mar 23 '15 at 07:01
-
Be specific on your question. I believe what I wrote here is already good enough for you to start your study on. – Adrian Shum Mar 23 '15 at 07:09