1 Reply Latest reply: Feb 25, 2013 8:46 AM by gimbal2 RSS

    Cocurrency in a web application

    javaMan2012
      Hi Folks,

      Asked this question before in another forum, no answer yet, so posting here as well. Just a question about concurrency. Let's say a person is developing an online booking system(could be movie booking, hotel room booking etc). How do you handle concurrecny for such an application? I mean issues like person B trying to book the same slot that person A is already in the process of booking. Does the web server (GlassFish,Tomcat,WebLogic etc) handle it 'automatically' where no intervention is required from the developer or does the developer actually need to write classes that implement the runnable interface or extend the thread class and use the synchronize keyword to lock the method? Please do advise. Thanks folks.

      regards
      John
        • 1. Re: Cocurrency in a web application
          gimbal2
          The server doesn't know what a booking is - how could it do anything for you? Your problem is also not about code synchronization - it is perfectly valid for two people to process a booking at the same time, it is only not valid to process the exact same booking at the same time.

          Me - I'd pretend that there is no such thing as two people booking the same slot at the same time - until the very last moment where you actually commit the booking to a particular person. One of them is going to be first and that's the winner, in the other's case before saving you'd check the database if it is already taken and then inform the user that he/she's out of luck. The stupid and easy solution that is also quite safe.