• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Single User Problem

 
Dhiraj Srivastava
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my application I want only one user to access a particular section at a time. The scenario is suppose I log in the application to change a customer address based on customerId. At the same time login in the application with the same customerId. Then other user see "A person is already working on this id".

However, I have solved this problem by using ServletConext Object.

----------------------------------------------
ServletContext sc = getServlet().getServletContext();
String sValid = "0";
if (sc.getAttribute("CurrentId_"+customerId)!= null)
sValid = 1;
else
sc.setAttribute("CurrentId_"+customerId,"1");

if (sValid.equals("1"))
<EXCEPTION THROWN THAT SOME USER IS WORKING>
----------------------------------------------

First time the case will be in else block. Second time system throws exception.

Now my concern is this how can I put this attribute to null. So that new user will be able to work.

I hope you people will understand.

Thanks in advance,

Dhiraj Srivastava
 
Satish Chilukuri
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dhiraj Srivastava:

Now my concern is this how can I put this attribute to null. So that new user will be able to work.


When User 1 is done with his operation (changing the address), remove the customerId attribute from the ServletContext. That way when a new user comes in, the ServletContext attribute will be null.

Also make sure that these operations are synchronized on the ServletContext object.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic