Meaningless Drivel is fun!
The moose likes EJB and other Java EE Technologies and the fly likes Concurrency in a web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Concurrency in a web application" Watch "Concurrency in a web application" New topic

Concurrency in a web application

John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 170
Hi Folks,

I hope this is the correct section to post this as it's a query related to web based technologies. 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.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Depends on which web technology you use. Servlets are multi-threaded, so you'd need to write them in such a way that they're thread-safe. Most web frameworks (like Struts, Stripes etc.) implement an abstraction that is single-threaded, so that the developer need not worry about that (Struts Actions or Stripes ActionBeans).

As regards the DB, you should use transactions so that it can detect any conflicts and fail them with an exception if necessary.
I agree. Here's the link:
subject: Concurrency in a web application
It's not a secret anymore!