• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about helper class of session bean

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gurus,
I need your help. I have been puzzled by this for a long time.
Thanks in advance.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic