Consider a persistent Hashtable which is to be accessed by any request to a
servlet. Here is an implementation, and since I have doubts about it I would
welcome comments.

First there is a wrapper-class intended to make the changes to data thread-safe
with 'synchronized'. Its methods mimic the ones in Hashtable class.

class QAHT {
  private Hashtable qaTable;
  QAHT(Hashtable qaTable) {
    this.qaTable = qaTable;
  }

  Object get(Object id) {
    synchronized(qaTable) {
      return qaTable.get(id);
    }
  }

  boolean containsKey(Object id) {
    synchronized(qaTable) {
      return qaTable.containsKey(id);
    }
  }
  .......
}// end of class QAHT

Then there is the variable qaMaint, defined as 'static'.

public class AuthorServlet extends HttpServlet {
    static QAHT qaMaint = new QAHT(new Hashtable());
    <the rest of the servlet>
}

It seems to work, but I have not tested it for thread-safe property. What's
wrong with it? Let's hear it. No mercy.

--
Alex Birman, IBM Watson Research Center, Hawthorne, N.Y.
[EMAIL PROTECTED], (914)-784-7275 (tie 863)

___________________________________________________________________________
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