| Author |
simple J2EE question
|
peter cooke
Ranch Hand
Joined: Mar 16, 2004
Posts: 310
|
|
I remember from one of my certification exams that method local variables are really the only true thread safe things. It stated that instance variables, and static things are most definitely not thread safe. So If I have a static method, that does not spin off any threads, all parameters are local, and does not spin off any threads. is it safe to assume the local variables are considered thread safe in a J2EE container public class fooHelper{ public static String bar(final Object obj1){ //do some work ArrayList al = baz(object1); // iterateOver array list String output createStringFromObjects(outputAL); return output } public static ArrayList baz(final Object obj1){ // do work Create array of annonymous inner classes } public static String createStringFromObjects(ArrayList al){ .../for each object in array list append output to StringBuffer return buffer.toString(); } }
|
CIAO Peter M. Cooke
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
Your own code is probably safe enough, but there are a couple unknowns here. Who passed you that obj1 parameter? If obj1 is already referenced by multiple threads it could be changing in bad ways in between the instructions in your code. What does createStringFromObjects do? We have no guarantee that it won't pass outputAL to several threads. Remember, you're not only having sex with obj1 but with every partner obj1 ever had sex with, and every partner they had, etc. Oh, I mean "threads". Yeah, that's what I think about all day long.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
 |
|
|
subject: simple J2EE question
|
|
|