• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using ArrayList / Vector in EJB

 
Jack Nicholson
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am encapsulating the data into a Vector in EJB for passing to JSP-BEAN(front end).
But as vector has synchronized access, & ArrayList is not synchronized,
vector is somewhat costly
May I know wheather it is safe to use it into EJB's.
Thanx in advance
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayList should be just fine unless you're handing out references to a shared instance. For example,is ok, butmight not be.
 
Amol Takate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public List getList() {
return this.list;
}

why will this cause a problem ???.
You can do this in stateful session beans.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can do this but the problem is you are returning
the same array list all the time. This means you have to
synchronize the access to your List.
In the first example it is always a new List, there it is no
problem.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think carefully about this problem guys. This is being used as an EJB return value. If it's a Local EJB then it will return a reference and you do have to think about synchronized access. However, if it's a Remote EJB, you'll always return a copy to the client -- it won't matter which you use.
Kyle
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!