Question:
Single session in Java?
Raheem
2007-04-16 01:21:42 UTC
I have a requirement wherein I need to give the session to only one user at a time. Only if that session is expired, then give that session to the next person in the queue. How can I do it in Java? Please provide me with a sample code?
Four answers:
downed.angel
2007-04-16 01:32:22 UTC
I can think of Two ways depending on your comfort level:



From Server Side: Make use of a singelton framework to ensure only one object is created at a time. Use this object to store user info session id, expiry time,etc. Modify the framework in such a way that along with creating a single object also ensure it is assigned to only one user at a time. To all others return a null.



From Client Side: (This will still involve some server side/JSP coding too). Create persistent cookies. Use your JSP to read info and session id from the cookie. If the cookie has expired allow other users to be redirected to the required resource otherwise, keep them waiting.
?
2016-12-20 21:00:20 UTC
i'm not partial to the different 2 solutions, so i will upload to this. those are the two words correct to cyber web programming. In cyber web programming between the problems is the inability of a unmarried stateful 'connection. each time a browser asks for an internet page it starts a sparkling connection to the server. this implies that there is constrained ability for one web page to acknowledge what you probably did on yet another (i'm over-simplifying slightly). This loss of statefullness is between the middle issues of cyber web purposes. A "cookie" is a browser time era, not a Java time era. A cookie is a touch suggestions that a internet site can ask the browser to keep in mind for it. the browser shops this cookie via server the two for the life of the browser window, or in all likelihood continuously. this delivers a internet site the flexibility to have some suggestions that connects requests mutually. The browser sends those cookie alongside with each request to the server. the main worry-unfastened and functional use of a cookie to to keep a unmarried identifier on the browser. This identifier is a "consultation" identifier which the server can use to % out all your strikes in a particular set of appropriate strikes on the positioning. so as a cyber web application, once you hit my web page i might ask your browser to set a cookie figuring out you as #12345. then, each request you browser truly says to me "I actually have a request from #12345 to confirm web page XYZ." i'm able to then use that huge style to look up suggestions on the server to keep in mind what you will been doing while you have been here. as an occasion you're able to have been on an internet page and requested me to kind effects via date as a exchange of alphabetically. Now i'm able to keep in mind that accross multiple pages, while with out it, properly...I nonetheless ought to, besides the fact that it may well be a lot greater arduous to software. Now, the time era consultation extremely ability a particular merchandise interior the Servlet specification. This consultation merchandise is called a super hashmap, besides the fact that it extremely is a hashmap that keeps to be alive and is offered for as lengthy because of the fact the person keeps to make requests speedier than some timeout era. i'm able to request the consultation from the request merchandise and stick suggestions in it that i choose for to apply later. Then, the subsequent request i'm able to get the consultation and locate the factor I positioned there. The above consultation identifier and cookie explains how that magic became carried out.
chandisha m
2007-04-16 01:59:39 UTC
refer to this site
anonymous
2007-04-16 01:27:16 UTC
Try with putty.exe


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...