• 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 two 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 of two helper classes?
Second case, if i didn't define helper class as static, then is it true that there are two hepler class for each bean instance? Is "synchronized" stilled needed? Why? In this case, can helper classes get the same concurrent control service from container as bean itself?
For the performance view, which case is better?
Thanks for your reply.
 
cindy wang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gurus,
I need your help. I have been puzzled by this for a long time.
Thanks in advance.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cindy,
If your session bean methods create new instances of the helper class then there is no need for synchronization. Synchronization is only necessary for shared data -- and in this case the instances would not be shared.
This is really not J2EE specific -- I'd suggest that you read up on standard threading principles in Java -- maybe Doug Lea's "Concurrent Programming in Java" might help.
Kyle
 
cindy wang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.
Since helper classes are just utility classes, I prefer to define them as static classes. Then it means all bean instances share the same helper objects. In this case, I should add "synchronized" to setter method, right?
From the perspective of performance, which is better--case 1, static helper classes shared by all bean instances with synchronization control; or case 2, each bean instance with its own helper class?
Thanks in advance.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do yourself a favor. Don't design for performance. Design for clarity. If performance becomes an issue than use a profiler to find out where the bottleneck is and fix it then and there.
[ October 02, 2002: Message edited by: Chris Mathews ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic