Redian新闻
>
question: how to implement this
avatar
question: how to implement this# Java - 爪哇娇娃
w*t
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!
avatar
h*b
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!

avatar
KG
3
Don't know what your environment is, but Singleton could be an option...

~~~~~~~JSP?

【在 h******b 的大作中提到】
: static class?
:
: ~~~~~~~JSP?

avatar
w*t
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?

avatar
n*k
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!

avatar
e*g
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.

avatar
p*y
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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。