Hi,

How much data you expect from your select boxes ??
If it is a small amount, I would suggest that you store it in a Vector and
save it as a application attribute.
Then you static methods can "query" the Vector instead.
You only need to update the Vector if there is any changes to the these
select boxes' data (I presume that will not happen often)

HTH


Best Regards,

Lim Yong How
Software Engineer
Ryeson Security International
180B Bencoolen Street #10-01/02 The Bencoolen Singapore 189648
www.ryeson.com <http://www.ryeson.com>

____________________________________________________________________________
________________________

The information contained in this e-mail message is intended only for the
use of the person or entity to whom it is addressed and may contain
information that is CONFIDENTIAL and may be LEGALLY PRIVILEGED and exempt
from disclosure under applicable laws. If you read this message and are not
the addressee you are notified that use, dissemination, distribution, or
reproduction of this message is prohibited. If you have received this
message in error, please notify us immediately and delete the original
message.
____________________________________________________________________________
__________________



-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Kesavanarayanan, Ramesh
(Cognizant)
Sent: Friday, 20 December, 2002 12:56 PM
To: [EMAIL PROTECTED]
Subject: static initialization


Hi all,

 I have a Helper class which has several methods. Each method willspeak
overto the DB and get the values as ArrayList. These values will be loaded
in the HTML pages as option values of the select boxes.


Here is the sample code snippet i have used . I have made the OWNER_LIST as
private static.
          private   static  ArrayList distinctOwner(String tableName)  {
                Connection conn = null;
                PreparedStatement pstmt = null;
                DBUtilities DBUtil = null;
               if(OWNER_LIST == null) {
                try
                  {
                         OWNER_LIST = new ArrayList();
                         DBUtil = new DBUtilities();
                         conn.setAutoCommit(false);;
                             String sql = "select distinct owner_name from "
+ tableName + " order by owner_name";
                             ResultSet rs = DBUtil.doSelect(sql);
                             while (rs != null && rs.next())
                             {
                                OWNER_LIST.add(rs.getString(1));
                             }
                            rs.close();
                  } catch (Exception e) {
                               System.err.println("Problem getting distinct
owner from " + tableName + " order by owner name");
                    }
                    finally {
                        try { pstmt.close(); } catch (Exception e) { }
                        try {
                               DBUtil.closeConnection();
                        } catch (Exception e) { }
                   }
                 }
                  return OWNER_LIST;
            }
I have made all these ArrayList  as static so that they will be populated
only once in the server. Typically I amtrying to catch the records.

Some transaction during the application may change the DB records.

 In such scenario i have to call a Refresh such that this makes all the
values of the Helper class again to null so that when next time somebody
clicks on some item Helper class has to fetch the new values from the DB.

 My question is supposing that when a user clicks on the Refresh buton and
at the same time some other user is looping thru the ArrayList in their jsp
pages, it will surely thro an error.

 How to prevent this.

I thought of putting the ArrayList initialization as synchronized but in my
Helper class i have many methods (25). That means i will be having 25
Synchronized blocks which might become too overhead for the webserver.

 Any nice ideas and suggestions to resolve this ishighly appreciated.

 Regards

 Ramesh Kesavanarayanan
 [EMAIL PROTECTED]
 +91-44- 811 3063 ext 2232 VNet- 42425

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to