depends - is the primary key a shared resource? usually for this kind of thing it
would be, so the answer in that case is no, you don't get threadsafety for free.
one simple way to ensure that you don't give out the same value to two (or more)
clients is to synchronize the method that you use to give out the keys:
public synchronized int getNextKey(){
return ++key;
}
which should ensure that you don't get two threads in there at once.
hope this helps,
-bml
Nanduri Amarnath wrote:
> Guys/Girls ,
> I am calling a servlet from a jsp. The servlet implements the
> SingleThreadModel.
> The servlet has a doPost() method that writes data to a table in the database.
> The primary key
> for each row of this Table is got by counting the ( number of rows in the Table
> + 1 ). This is done in the
> doPost() method. Also i am setting autoCommit() to false ( in the Connection
> Object ) and doing either a
> complete commit() or a complete rollback().
>
> My question is... if different people hit this page simultaneously, will i still
> be getting unique primary keys for every person
> (or) if not is there a better way to do it......... Thanks in advance.
>
> Cheers,
> Amar..
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
--
_________________________________________________________________________
Brian M. Long RandomWalk Computing, Inc. [EMAIL PROTECTED]
'Apollo was astonished / Dionysus thought me mad' -Hemispheres, 14:28
__________________________________________________________________________
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html