This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple J2EE question

 
peter cooke
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}

}
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic