• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
  • Frits Walraven
  • fred rosenberger
  • salvin francis

defining static araylist in stateless session ejb

Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
I am new to EJb's.
I have a list of values which i need to compare with each of the values in the vector
passed to the method. I have 4-5 methods to which diffrent values will be passed but i need to check the values against same(common) list of values.
For ex. i have ( val1,val2,vl3,val4)
i need to compare if the vector contains any of the above values then perfrom action
Following are the questions i need help with.
1. what collection will be most efficient to define to contain the values:
I am thinking of ArrayList
ex. ArrayList testal = new ArrayList();
2. since In 3-4 methods i need to compare agaist the same arraylist
so instead of declaring the Arraylist in each of the methods i am thinking of defining it
only once and to reference in each method.
will defining the Arralylist as static will be better?
so instaed of above definition
i will define it as
private static ArrayList testal = new ArrayList(4);
3. where should i put the try catch block for more efficient output.
My beab is as follows:
public class TestBean implements SessionBean {
private final static boolean VERBOSE = true;
private SessionContext ctx;
private int tradeLimit;
public final static String testurl = "http://localhost/testapp/";
public void setSessionContext(SessionContext ctx) {
log("setSessionContext called");
this.ctx = ctx;
public void ejbCreate() throws CreateException {
log("ejbCreate called");
try {
InitialContext ic = new InitialContext();
} catch (NamingException ne) {
throw new CreateException("Failed to find environment value " + ne);
private static ArrayList testal = new ArrayList(4);
public String Name1( Vector id) {
try {
for (int i = 0; i < id.size(); ++i)
String name = (String) id.elementAt(i);
if (!(testal.contains(name))){
System.out.println("valid name string " +name);}
public String Name2( Vector id2) {
try {
for (int i = 0; i < id2.size(); ++i){
String name = (String) id2.elementAt(i);
if (!(testal.contains(name))){
System.out.println("valid name string " +name);}

    Bookmark Topic Watch Topic
  • New Topic