It depends on how you structure the utility classes. For every request, if
you are creating a new instance of the utility class, you don't have to
synchronize it. But if you are using a singleton utility object (Shared
across requests), then you need to.

e.g

Case 1
-------

public class Utility {
   String attrA;
   String attrB;

  int methodA() {};
  int methodB(){};
}

In your servlet1 (DoGet or DoPost)/JSPPage1 code,
Utility aUtility = new Utility();
aUtility.methodA();

In your servlet2/JSPPage2 code,
Utility aUtility = new Utility();
aUtility.methodA();


Case 2 Singleton Object
-------

public class Utility {
   String attrA;
   String attrB;

  private Utility() {
  }

  private Utility a_Utility = null;

  static private a_Utility = null;
  static Synchronized public Utility instance() {
     if (a_Utility == null ) a_Utility = new Utility();
     return a_Utility;
  }

  ..
  synchronized static int aMethodA() {
    ..
  }
}

In your servlet1/JSPPage1 code,
   Utility.instance().methodA();

In your servlet2/JSPPage2 code,
   Utility.instance().methodA();

Sree


>From: Marc Krisjanous <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
>        Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: synchronized calls to utility classes??
>Date: Sun, 4 Jun 2000 16:37:36 -0500
>
>Hi all,
>Sorry to post this message again but I did not get any replies.....
>I have a servlet that creates utility classes for certain requests.  The
>utility classes have instance variables.  Do I need to synchronized the
>instantiation and method calls from the servlet to the utility classes?
>The
>utility classes manipulate data sent from client in request object.
>
>Cheers
>
>Marc
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to