can anybody provide me a simple example of concurrency control in servlet

B

bighead4694

Hi,

I am using jsp/servlet to create a web application. In this
application, i need to insert new users into db. but before insertion,
i have to check whether the user has already been in the db. I think
concurrency control should be used, but I have no idea how to achieve
concurrency control or transaction management in servlet. Can anybody
give me a simple example? Thanks!

bighead4694
 
N

nuklea

forget about concurrency stuff, create your table schema correctly and
let the db engine handle duplicate record. in your code just check the
return code after the insertion attempt.
 
W

Wendy S

I am using jsp/servlet to create a web application. In this
application, i need to insert new users into db. but before insertion,
i have to check whether the user has already been in the db. I think
concurrency control should be used, but I have no idea how to achieve
concurrency control or transaction management in servlet. Can anybody
give me a simple example? Thanks!

This doesn't have anything to do with JSP or Servlets. If you can't do it
with "regular" Java code, learn how to do that first, and build a set of
classes that interacts with the database. Then call those from your
Servlet.
 
A

anonymous

Hi,

I am using jsp/servlet to create a web application. In this
application, i need to insert new users into db. but before insertion,
i have to check whether the user has already been in the db. I think
concurrency control should be used, but I have no idea how to achieve
concurrency control or transaction management in servlet. Can anybody
give me a simple example? Thanks!

bighead4694
Is this a school project? Normally, you'd use constraints aka
referential integrety. This would prevent duplicates.
 
B

bighead4694

Hi,
I am able to code the java classes to interact with the database. but i
am not able to code the java classes to achieve the concurrency control
or transmission management. This web application is part of my thesis
project. My supervisor checked my codes and suggested me imporve the
concurrency control stuff. To be honest I have no idea about it. Do you
have any simple examples that can help me through?
 
A

Ann

Hi,
I am able to code the java classes to interact with the database. but i
am not able to code the java classes to achieve the concurrency control
or transmission management. This web application is part of my thesis

What grade are you in?
 
J

John C. Bollinger

I am able to code the java classes to interact with the database. but i
am not able to code the java classes to achieve the concurrency control
or transmission management. This web application is part of my thesis
project. My supervisor checked my codes and suggested me imporve the
concurrency control stuff. To be honest I have no idea about it. Do you
have any simple examples that can help me through?

So your DB access object requires a method insertNewUser(...) that
performs the check and insert. If this is the only way that users will
be added, if they will never be removed, and if only one instance of the
DB access class can ever be in use at a time, then it is sufficient to
just synchronize that method. In any other case you need a shared
synchronization object on which to synchronize the bodies of methods
that add, remove, or query the presence users in the DB.

You can exert control over DB transactions (if the DB itself and its
driver support it) by invoking Connection.setAutocommit(false), and then
using Connection.commit() and Connection.rollback() to commit or roll
back transactions where appropriate.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top