This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

defining static araylist in stateless session ejb  RSS feed

 
peter brews
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!