w******t 发帖数: 1422 | 1 Hi All,
I want to implment a class which gets instantiated only once per session.
Is there a way to do this? (I am out of idea on this now)
Thanks a lot! | h******b 发帖数: 312 | 2 static class?
~~~~~~~JSP?
【在 w******t 的大作中提到】 : Hi All, : I want to implment a class which gets instantiated only once per session. : Is there a way to do this? (I am out of idea on this now) : Thanks a lot!
| KG 发帖数: 515 | 3 Don't know what your environment is, but Singleton could be an option...
~~~~~~~JSP?
【在 h******b 的大作中提到】 : static class? : : ~~~~~~~JSP?
| w******t 发帖数: 1422 | 4 singleton is one per app (in clustered environment, maybe one per jvm, if not
very strict) - not an option
I need one per session - sort of like stateful session bean, but I don't want
to use ejb, is this possible?
session.
【在 KG 的大作中提到】 : Don't know what your environment is, but Singleton could be an option... : : ~~~~~~~JSP?
| n*****k 发帖数: 123 | 5
Are you using servlet? if do, you may first use
HttpServletRequest.getSession(false) to check if there is a session associated
with the request, then you can either create a new instance of this class and
then using HttpSession.putValue() method to store this new instance within the
session, or just retrive the instance from the session object.
Hope this will help.
【在 w******t 的大作中提到】 : Hi All, : I want to implment a class which gets instantiated only once per session. : Is there a way to do this? (I am out of idea on this now) : Thanks a lot!
| e***g 发帖数: 158 | 6 singleton doesn't mean single, it's about controlled instantiation.
class Foo
static public Foo getInstance(Session session){..}
this will work for you, right?
【在 w******t 的大作中提到】 : singleton is one per app (in clustered environment, maybe one per jvm, if not : very strict) - not an option : I need one per session - sort of like stateful session bean, but I don't want : to use ejb, is this possible? : : session.
| p***y 发帖数: 79 | 7 you can use similar idea as in singleton.
【在 w******t 的大作中提到】 : singleton is one per app (in clustered environment, maybe one per jvm, if not : very strict) - not an option : I need one per session - sort of like stateful session bean, but I don't want : to use ejb, is this possible? : : session.
|
|