Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes Question about helper class of session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Question about helper class of session bean " Watch "Question about helper class of session bean " New topic
Author

Question about helper class of session bean

cindy wang
Greenhorn

Joined: Sep 29, 2002
Posts: 10
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

Joined: Sep 29, 2002
Posts: 10
Hi Gurus,
I need your help. I have been puzzled by this for a long time.
Thanks in advance.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
cindy wang
Greenhorn

Joined: Sep 29, 2002
Posts: 10
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

Joined: Jul 18, 2001
Posts: 2712
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about helper class of session bean