Is that what this thread code safe?

I've been seeing some information that makes me think that some servlet code that I have that I thought is thread-safe is not really. I have a servlet that takes a POST request and calls a stored procedure on a database to do a few inserts.
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
  // Check validity of request then proceed.
  if (valid) { postPayment(request); }
}

synchronized private void postPayment(HttpServletRequest request)
{
  /* Take some parameters from the request and call the stored procedure */
}
What I'm trying to do, is make sure 2 queries containing the same data trying to insert to the database at the same time. I did that or do I need a different approach?

Meatwad says:
Yes, I say an EJB.

This isn't something that I can help you. There is here a forum EJB (Enterprise JavaBeans which can be a more appropriate place for this question.

For the logical database are simply referring to the lock table/row?

No, I mean no transactions. Google for something like java transaction database examples for more details. While you cannot end up using such things directly if the EJB ends up handling for you (and I really don't know how they do it), it is probably that you should know the basic principles.

And can you point me in the right direction to find more information on how do this using the EJB?

Google for the EJB tutorials and examples, for EJB transactions maybe, the link to the forum above.

Tags: Java

Similar Questions

Maybe you are looking for

  • Satellite C660-268 does not start, no start screen

    My laptop Toshiba Satellite C660-268 was installing updates, then it froze for half an hour, I decided to force quit by pressing the power button. I tried power, portable could not wake up, I can hear the fan but screen is not black, no post/splash s

  • Word question on iPad Pro 9.7 inches 9.3.1 mail app

    I can't open word documents by e-mail in the word app when I try everything freezes. App otherwise works perfectly and I am fully subscribed and released. Have you tried to restart. Help

  • Satellite M35-S456: hit error - recovery 'Thotkey' failed

    My laptop Satellite M35-S456 of 2004 Gets an error during startup. Titled "Wrong hit", he said:"'Thotkey' recovery failed. Error code: 0 x 00031402, 0 x 00000002. » I can use my touchpad, but I can't use the Fn key or the Play, Stop, forward, backwar

  • Stream video to Apple TV and listen to music at the same time iMac

    Can I stream media (audio + video) for Apple TV and listen to music on my iMac at the same time? (While my TV and my iMac will play two different audio streams). For example, my parents would watch a movie of my iMac on their TV HARD drive (connected

  • BOOTMGR is missing, press ctrl + alt + delete to restart

    So I found out that I have no boot disk, if windows does not start - I need to insert an installation disc that I did not. I am currently using windows vista - if I were to insert a floppy disk in windows 8, I would be able to install this later vers