in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 69 70 71 72 73 74 < 75 > 76 77 78 79 80 81 .. 166 >> Next

until the end of every month. The downside of this solution was our understanding that the relevance of the document data could be diminished if older, less significant data was cached and rendered on user queries. Our final solution involved the implementation of two innovative open-source applications: the OSCache tag library from OpenSymphony and the JMeter application from the Apache Software Foundation. OSCache tags were used to cache database queries, and JMeter was used to emulate user requests.
Our aim was to cache the sections of our code where database queries were performed so that repeat trips back to the database could be avoided, thereby increasing performance. During normal operations, any new documents that were added to the database repository would be cached upon insertion. The caching process would be facilitated by implementing JMeter scripts with URL parameters that emulated all the different combinations of user responses. We determined that our entire site could be cached in 45 minutes every month.
To demonstrate this process, some example JavaServer Pages (JSPs) and JMeter XML ThreadGroup scripts were developed to cache query data from a simple MySQL database. The Web page shown in Figure 23.1 demonstrates two portlet-like tables with information items: Bike Trails, Gyms, and so on, and the 50 different U.S. states where these information items can be found, which would total 550 different link combinations. The caching process could have been performed manually by hitting each page with the OSCache tags, but this would take too much time and effort. We felt that a more efficient process would involve the creation of a test generation application and the implementation of JMeter to run those tests.
3 Cache Example - Microsoft Internet Explorer provided by Home
File Edit View Favorites Tools Help
+*Back * Search _*j Favorites ^History | ^ ?
Address |?] http7/tocaltotf:8080/cache/home.f$p?&stale=Aikan$asitopidd=Re$tauant$ 2] ^Go Links **
Go ^SearchWeb ^SearchSite Page Info - f?lUp >HigWgM.
Cache Example
Automobile Dealers
Bike Trails
Gvms Hospitals
Pet Stores
Rest Areas Supermarkets

I Arkansas Bl
California Colorado Connecticut J
IState lArkansas
Flower Apple Blossom
Bird Mockingbird
Capital Little Rock
|State: Arkansas
Larrys BBQ

a Start | ' 51 @
I Co.
iTo llelCa...
I Co..
I Co.
gjr Local intranet <ا)<92] 8:32 AM
Figure 23.1 Cache example application.
202 Item 23
The main focus of our implementation (see Listing 23.1) is a JSP named home.jsp because it renders dynamic query information to the user display and uses the OSCache tag library to cache that data. In the home.jsp code below, the tag library OSCache is specified on line 07. The URI for this class is specified in the deployment descriptor (web.xml). Please note that the <cache:cache></cache:cache> tags on lines 31 to 40 surround the content.jsp page include, which actually performs the database query. On line 31, we set the cache duration using the ISO-8601 format (YYYY-MM-DD). We could have also set the caching duration using the time attribute, whose default value is 3600 seconds, which is 1 hour.
01 <%@page import="java.util.*" %>
02 <%@page import="*" %>
03 <%@page import="java.sql.*" %>
05 <jsp:useBean id="cacheHelper"
06 class="org.javapitfalls.item23.cacheHelper" scope="request"/>
07 <%@ taglib uri="OSCache" prefix="cache" %>
09 <%
10 String topicId = request.getParameter("topicId");
11 String state = request.getParameter("state");
12 if (topicId == null) topicId = "";
13 if (state == null) state = "";
14 %>
16 <title>
17 Cache Example
18 </title>
20 <jsp:include page="header.jsp" >
21 <jsp:param name="topicId" value="<%= topicId %>" />
22 <jsp:param name="state" value="<%= state %>" />
23 </jsp:include>
25 <table border="1" width="100%">
26 <tr valign="top">
27 <td width="25%" valign="top">
28 <jsp:include page="leftNav.jsp" />
29 </td>
30 <td width="75%" valign="top">
31 <cache:cache scope="session" duration="2002-01-31">
32 <% try { %>
33 <j sp:include page="content.j sp"/>
34 <jsp:param name="topicId" value="<%= topicId %>" />
35 <jsp:param name="state" value="<%= state %>" />
36 </j sp:include>
37 <% } catch (Exception e) { %>
Listing 23.1 home.jsp
Cache, It's Money 203
38 <cache:usecached />
39 <% } %>
40 </cache:cache>
41 </td>
42 </tr>
43 </table>
46 <jsp:include page="footer.jsp" />
Listing 23.1 (continued)
The OSCache tag library implementation includes a properties file that is installed in the /WEB-INF/classes directory, which allows the user to set attributes for operational preferences. We've included only the properties that are pertinent to our implementation in Listing 23.2. The cache.path property points to the location where we want to place our cache files. The cache.debug property specifies that we want to see debugging messages, and the cache.unlimited property ensures that the cache disk space is unlimited.
Previous << 1 .. 69 70 71 72 73 74 < 75 > 76 77 78 79 80 81 .. 166 >> Next