This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes simple J2EE question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple J2EE question" Watch "simple J2EE question" New topic

simple J2EE question

peter cooke
Ranch Hand

Joined: Mar 16, 2004
Posts: 317
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
I agree. Here's the link:
subject: simple J2EE question