• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about helper class of session bean

 
cindy wang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a session bean, which calls some methods of some helper classes( utility class). Since helper classes only provide some utilities, I'd like to define them as static classes.
In the context of container, bean is of no concern about multiple client access. But what if multiple bean instances access to single helper class? Is it necessary to add "synchronized" to some methods ?
Second case, if i didn't define helper class as static, then is it true that there is one hepler class for each bean instance? Is "synchronized" stilled needed? Why? In this case, can helper class get the same concurrent control service from container as bean itself?
For the performance view, which case is better?
Thanks for your reply.
 
Vin Kris
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cindy, by saying static helper classes, i assume you meant to say a Class with only static methods.
First, synchronized access is required only if you want to prevent concurrent access to the same piece of data - to maintain data integrity for any thread.
In the context of your helper class, you need to synchronize the methods only if they are modifying the class variables - which have to be static since the static methods can only only access static members.
But when you synchronize a static method, the whole class (instance of class java.lang.Class that is the runtime representation of this class) gets locked and no other static synchronized method can be executed.
So, if you have no data members in the class - synchronize is not needed.
If the methods are not static - then you would abviously have to create a new instance whenever you need it. Then, regardless of whether the class has data members, synchronize is not needed.
btw, the concurrent control performed by the container on the Session beans is not extended to any objects created by the beans.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!