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


This e-mail and any files transmitted with it are for the sole use of the intended 
recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient, please contact the sender by reply e-mail and 
destroy all copies of the original message.
Any unauthorised review, use, disclosure, dissemination, forwarding, printing or 
copying of this email or any action taken in reliance on this e-mail is strictly
prohibited and may be unlawful.

                Visit us at http://www.cognizant.com

Reply via email to