Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Concurrency in a web application

 
John Paterson
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

regards
John
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic