Hi there, I'd like to have some feedback on this pattern which uses a singleton class to pass an ObjectMessage to a Message Driven Bean. What you think and how you would improve it. The code shown belowe belongs to the client classes based on struts
Havent spent much time on the code, but one thing that comes to my mind is why would you make the MDBMessage singleton. Furthermore, the session and other objects like the sender are created in the constructor of this *singleton* class which means that once the ShutDownPlugin closes the session, there's no way to recreate the session and the related objects because the constructor of this singleton MDBMessage will not be called again.
Going by this singleton approach, you are going to end up having a single connection and session sending all the messages. This means that the connection will be open throughtout the lifecycle of the application. This would not be a good idea.
As these properties are common used by other classes, I though it was a good idea reduce the code
As far as reducing the code is concerned, you can still achieve that by having this connection/session creation in a utility class which is not a singleton.
Joined: Dec 23, 2005
Thanks for your reply, but why is not a good idea? You mean memory leaks? At least I know that only one instance is using that session and therefore I perhaps minimize that risk.
With the number of posts in this forum increasing because of the book promotion, lost track of your post. Sorry about that
but why is not a good idea?
Going by the singleton approach, you are keeping one single connection open for the entire lifetime of the application. What if the connection timeouts (or breaks for some reason), you wont be able to recover since with the current design there's no way the connection will be recreated. Just my thought, let us know if you feel otherwise.