aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple J2EE question" Watch "simple J2EE question" New topic
Author

simple J2EE question

peter cooke
Ranch Hand

Joined: Mar 16, 2004
Posts: 314
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: http://aspose.com/file-tools
 
subject: simple J2EE question