Discussions

General J2EE: Use static method or instantiate a class

  1. Use static method or instantiate a class (2 messages)

    Folks,
    We have an exception handler class that I am adding code to provide email notification. My question is when I'm in the body of the exception handler should I call the EmailNotification by passing the exception and Class context to a static method or do I need to instantiate a new EmailNotification type class, then call a notify type method.

    To make things plain, is there anything wrong with calling a static method in another class? Or is it for some reason better to instantiate a new object of that class then invoke the desired method.
    It would seem to me that the static method would be less weight but is there something I'm missing, any concurrency issues?

    Please advise, thanks!
  2. To make things plain, is there anything wrong with calling a static method in another class? Or is it for some reason better to instantiate a new object of that class then invoke the desired method.It would seem to me that the static method would be less weight but is there something I'm missing, any concurrency issues?Please advise, thanks!

    creatign a new instance would only create a new object to be garbaged later. If your static methos is stateless - I don't see why a methods that sends mail wouldn't be - then there are no concurency issues.

    hope it helps,
    Emil ( http://www.thekirschners.com/software/testare/testare.html )
  3. Gracias.