• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
accordingly.
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();
testal.add("val1");
testal.add("val2");
testal.add("val3");
testal.add("val4");
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);
testal.add("val1");
testal.add("val2");
testal.add("val3");
testal.add("val4");
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);
testal.add("val1");
testal.add("val2");
testal.add("val3");
testal.add("val4");
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);}
}catch{}
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);}
..
}
}catch{}

Thanks,
smita
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic