• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

simple J2EE question

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();

(instanceof Sidekick)
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.
The fastest and most reliable components of any system are those that are not there. Tiny ad:
professionally read, modify and write PDF files from Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!