由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 简单的EJB问题
相关主题
Stateful session bean到底有啥好处?请教一下JSP+SERVLET结构的进阶教材,多谢了
请问一个问题Difference btw EJBLocalHome and EJBHome?
java servlet httpsession问题求教interview求助
JSP+SERVLET网站一般用下面方式来保存和传递变量和参数光学Java Standard 本身是不是永远不够?
急问:shoppingcart在eCommerce中究竟如何实现?有经验的同志谈谈JDO吧?
Re: EJB and its Future (Discussion welcomed)Questions on EJB3 Persistence/Hibernate
关于EJB开发的几个问题Tomcat Servlet: synchronized vs non-synchronized methods
One more servlet Q: Http SessionSocket created/called in Servlet timed out
相关话题的讨论汇总
话题: list话题: slsb话题: ejb话题: bean话题: servlet
进入Java版参与讨论
1 (共1页)
c***k
发帖数: 1589
1
不同的client之间如何共享数据?
比如我现在有一个List,有一个stateful sessionbean可以访问这个list
在servlet中,会初始化一个static sessionbean instance
servlet will call method in this sessionbean to get the list
So every web client will ask servlet for this list
(this list is not persisted)
My problem is, it seems like I will get concurrentaccess exception
because if several clients happen to ask for the servlet for the same time.
What's the correct/simple way to implement such scenario?
A**o
发帖数: 1550
2
make it a Vector. //grin

.

【在 c***k 的大作中提到】
: 不同的client之间如何共享数据?
: 比如我现在有一个List,有一个stateful sessionbean可以访问这个list
: 在servlet中,会初始化一个static sessionbean instance
: servlet will call method in this sessionbean to get the list
: So every web client will ask servlet for this list
: (this list is not persisted)
: My problem is, it seems like I will get concurrentaccess exception
: because if several clients happen to ask for the servlet for the same time.
: What's the correct/simple way to implement such scenario?

c***k
发帖数: 1589
3
Seriously ^^
What's the simplest way to share data between sessions?
Can I use another singleton session bean to serve as an repository?
Thanks
g*****g
发帖数: 34805
4
If all the threads are read only, then you should have no problem.
Otherwise, you should declare transaction. You can check how to
do declarative transaction in your EJB container.
Usually, data is shared through DB.

.

【在 c***k 的大作中提到】
: 不同的client之间如何共享数据?
: 比如我现在有一个List,有一个stateful sessionbean可以访问这个list
: 在servlet中,会初始化一个static sessionbean instance
: servlet will call method in this sessionbean to get the list
: So every web client will ask servlet for this list
: (this list is not persisted)
: My problem is, it seems like I will get concurrentaccess exception
: because if several clients happen to ask for the servlet for the same time.
: What's the correct/simple way to implement such scenario?

s******e
发帖数: 493
5
in java 5.0+, copyonwritearraylist can be a candidate. Please read api for
info when to use it.
another solution is trying to sychronize all access to that list (both
mutative and nonmutative operations) depending on your biz requirements. it
can be very expensive. this is pretty much bringing the concurrency to your
knees. So be careful.
the third one is something like optimistic locking. probably you also need
read-consistency. It will be quite complex. I am not sure if you want to go
for tha
c***k
发帖数: 1589
6
I see. So the normal way to share data is through DB (entity Bean in EJB2).
Thanks for all the replying. :)
t*******e
发帖数: 684
7
Stateful session beans are designed to be used within a session scope,
meaning, different bean instances of the same bean class are instantiated to
maintain client-specific data. If you make a SFSB application scope --
shared by all client sessions, EJB containers are supposed to raise a
concurrent access exception according to the EJB specification. In WebLogic,
you may specify "allow-concurrent-calls" to be true in weblogic-ejb-jar.xml
file to override the default behavior. However, it is stil
c***k
发帖数: 1589
8
So, if shared information needed to be passed between sessions. We can
either use Message-driven bean or through DB. Right?
t*******e
发帖数: 684
9

There are different means to share data across web sessions.
An object stored in ServletContext, a stateless session bean (readonly),
SFSB with DB access...

【在 c***k 的大作中提到】
: So, if shared information needed to be passed between sessions. We can
: either use Message-driven bean or through DB. Right?

g*****g
发帖数: 34805
10
It all comes down to whether the data should be persisted.
If it should be, then I would use slsb with DB access.
If not, then slsb with synchronized access if RW.
I would never use sfsb to share data across sessions.

【在 t*******e 的大作中提到】
:
: There are different means to share data across web sessions.
: An object stored in ServletContext, a stateless session bean (readonly),
: SFSB with DB access...

c***k
发帖数: 1589
11
Can I use synchronized method inside SLSB?
I remembered somewhere it said we shouldn't use static field or synchronized
method in the EJB.
t*******e
发帖数: 684
12

synchronized
You don't have to synchronize the method. Instance pooling in SLSB makes
sure that one instance of SLSB is allocated per thread. That is why SLSB is good
for read only operations. If you do updates, you need more complicated
approaches to synchronize data changes, e.g., database persistence.

【在 c***k 的大作中提到】
: Can I use synchronized method inside SLSB?
: I remembered somewhere it said we shouldn't use static field or synchronized
: method in the EJB.

w******f
发帖数: 620
13
Just make sure your session bean is thread safe, otherwise I suggest you
make the session bean as the local variable inside your service() method.
1 (共1页)
进入Java版参与讨论
相关主题
Socket created/called in Servlet timed out急问:shoppingcart在eCommerce中究竟如何实现?
本菜对EJB一问Re: EJB and its Future (Discussion welcomed)
EJB框架示意图关于EJB开发的几个问题
Another nice EJB server(recommend ;-)One more servlet Q: Http Session
Stateful session bean到底有啥好处?请教一下JSP+SERVLET结构的进阶教材,多谢了
请问一个问题Difference btw EJBLocalHome and EJBHome?
java servlet httpsession问题求教interview求助
JSP+SERVLET网站一般用下面方式来保存和传递变量和参数光学Java Standard 本身是不是永远不够?
相关话题的讨论汇总
话题: list话题: slsb话题: ejb话题: bean话题: servlet