This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prevent simultaneous access on JSP

 
vivek dhiman
Ranch Hand
Posts: 153
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have one jsp page that i use to drill down the report. Challenge is if any user running that report, if other user trying to access that page, it should be prevent. Means at one time only one user should be able to access that page & when he close the window other should be accessible that jsp page.

Thanks.
 
Balaji Vankadaru
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
place your code which need to be prevented from access buy second person in a synchronization block . It ensures that no two threads can access the same code at once.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good design would notify the 2nd user with a "Busy, try again later message"

If this report generation takes longer than a couple of minutes you have a bad design - the HTTP request / response cycle should execute quickly.

Bill
 
vivek dhiman
Ranch Hand
Posts: 153
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for response.

Actually what the issue is, i want to stop the request to access genReport.jsp if same jsp page is accessed by other user. Like if this jsp is opened on one user machine & other user logged on separate machine, it should be prevent to serve other user request (page should display alert or we can redirect to other page) & if first user close the window of that particular jsp. it should now will available to process other user request.

Thanks
 
Ganesh Malaichamy
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with William Brogden. Even though your requirement to lock the page can be fulfilled by some means that may not be a clean solution.From your use case you are trying to lock the page based on a session.Then you have to think about session timeout also.You can add HTTP Session Listener and track the usage of that particular page.
 
Niju Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can implement this by using synchronize in java
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vivek dhiman wrote:Challenge is if any user running that report, if other user trying to access that page, it should be prevent.

Why is that? What's the problem with multiple users running a report simultaneously?

Web apps are inherently multi-threaded and multi-user. Instead of trying to prevent that, you should learn how to wrote web apps that can handle concurrency. And, of course, and reporting logic should not be part of the JSP, but instead in a servlet or a backing bean or a helper class.
 
Niju Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what Ulf Dittmer told is the good practice you should follow. You need to block your part of businesss logic if one user is doing the action. I think you tried to block your jsp page because you have writtened the logic in the .jsp page itself in the scriptlet. If you done like so it is not good practice. Do in structured way and separate your view and logic. And you can do what you need in your your logic part by using synchronization not in your view page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic