I Scjp on the online test
Abstract: On my Scjp online testing
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="271" height="86" align="center" valign="top"> </ td> <td width="413" valign="top"> on my Scjp Online testing, a summary.
I use the database connection pool is proxool.
I look at the cache strategy: if the database in 1000 that first one from the database that a random read 300 Add in the cache memory, where a cache of expired when questions from the remaining 700 Title take a random test questions to replace expired. JSP pages from the memory cache that the 300 randomly selected from 60 title. This fully consider the response speed of the page, users will not be slow to react to that website and complain or leave. And those who take the test online more speed, it is not affected because there is no expired questions, or to access the database, all the questions removed from the memory cache.
Concrete realization of the following for information.
</ Td> </ tr> <tr> <td height="14" colspan="2">
</ Td> </ tr> </ table>
First, in the category of object ScjpVObj fields in the database and fields questions Table corresponding package com.java3z.data; import java.io.Serializable; import java.util.Date; public class ScjpVObj implements Serializable (int id = 0 ; String content; / / test the contents of String option; / / Item String explain the number of options; / / int test_type Comments answer; / / item types, radio: 0 multiple-choice: a String answer; / / The answer questions int score; / / test scores Date qdate; / / add period of questions public ScjpVObj () () public ScjpVObj (int id, String content, String option, String explain, int test_type, String answer, int score, Date qdate) (id = this.id; this.content = content; this.option = option; this.explain = explain; this.test_type = test_type; this.answer = answer; this.score = score; this.qdate = qdate;) public int getId () (return id;) public String getcontent () (return content;) public void setcontent (String content) = (this.content content;) public String getoption () (return option;) public void setoption (String option) (this.option = option;) public String getExplain () (return explain;) public void setExplain (String explain) = (this.explain explain;) public int getTest_type () (return test_type;) public void setTest_type (int test_type) = (this.test_type test_type;) public String getAnswer () (return answer;) public void setAnswer (String answer) (this.answer = answer;) public int getScore () (return score;) public void setScore (int content) = (this.score score;) public Date getQdate () (return qdate;) public void setQdata (Date qdate) = (this.qdate qdate;)) Second, I cache-cache management system use the revenue JCS. Package com.java3z.data; import java.sql .*; import org.apache.jcs.JCS; import org.apache.jcs.engine.behavior.IElementAttributes;
/ ** Note: Let count in a database that can be used, the questions of ID must be continuous, with a preservation of the array of questions ID, * for (int i = 0; i <count; i + +) * a [i] = i +1; * then the value of elements in an array upset, random array of questions in the database, ID * for (int i = 0; i <count; i + +) (* int j = (int) (Math. random () * count); * int temp = a [i]; * a [i] [j] = a * a [j] = temp;) * * 300 from the former test (a test for the ID [0 ] to a [299]) Add cache. questions id if a cache expired, and that the back from 300 * (ID test for a [300] to a [count-1]) were obtained from ID, replace expiring id and the questions, this would ensure that the cache questions constantly updated. * / Public class ScjpVObjManager (private static ScjpVObjManager instance; private static JCS scjpCache; private static int a [];// preserve all questions in the database ID number, private static int count; / / item in the database the number of private ScjpVObjManager () / / constructor function (Statement stmt = null; Connection conn = null; ResultSet rs = null; ScjpVObj vobj = null; try scjpCache = (JCS.getInstance ( "scjpCache"); conn = DriverManager.getConnection ( "proxool.Access"); stmt = conn.createStatement (); rs = stmt.executeQuery ( "select count (*) from examination3"); rs.next (); rs.getInt count = (1) / / database access to a number of questions = new int [count]; for (int i = 0; i <count; i + +) a [i] = i +1; / / ID database, is a start for (int i = 0; i <count; i + + ) (/ / value of elements in an array of disruption, random array of questions in the database ID, int j = (int) (Math.random () * count); int temp = a [i]; a [i] = a [j]; a [j] = temp;) for (int i = 0; i <300; i + +) (rs = stmt.executeQuery ( "select * from examination3 where id =" + a [i]); while (rs.next ()) (int id = rs.getInt ( "id"); String title = rs.getString ( "content"); String content = rs.getString (the "option"); String explain = rs. getString ( "explain"); int test_type = rs.getInt ( "test_type"); String answer = rs.getString (the "answer"); int score = rs.getInt (the "score"); Date qdate rs.getDate = ( "qdate"); vobj = new ScjpVObj (id, content, option, explain, test_type, answer, score, qdate); scjpCache.put ( "ScjpVObj" + i, vobj); / / Add to test memory cache ))) catch (SQLException e) (System.err.println (e.getMessage ());) catch (Exception e) (System.err.println (e.getMessage ());) finally (try (stmt.close (); conn.close ();) catch (SQLException ex1) (System.out.print (ex1);))) / ** * Singleton access point to the manager * / public static ScjpVObjManager getInstance () (synchronized ( ScjpVObjManager.class) (if (instance == null) (instance = new ScjpVObjManager ();)) return instance;) / ** * Retrieves a ScjpVObj. Default to look in the cache * / public ScjpVObj getScjpVObj (int id) (return getScjpVObj (id, true);) public ScjpVObj getScjpVObj (int i, boolean fromCache) / / id must be 0 <= id <= 299 (if (i <0 | | i> 299) return null; / / simple Treatment ScjpVObj vobj = null; / / First, if requested, and attempt to load from cache if (fromCache) (vobj = (ScjpVObj) scjpCache.get ( "ScjpVObj" + i);) / / If not in the cache memory test ID, for a [i] questions, then exchanged a [i] and a [300], in order to ensure that each admitted that not the same, to ensure that a [300] is random. If (vobj == null) (for (int k = 300; k <305; k + +) (/ / disrupt the five elements in the order of questions in the Q & A at least 305 int j = (int) (300 + ( int) (Math.random () * (count-301))); int temp = a [k] a [k] = a [j]; a [j] = temp;) int t = a [i] ; a [i] = a [300]; a [300] = t; vobj = loadScjpVObj (i); / / from the database from that return vobj);) public ScjpVObj loadScjpVObj (int i) (ScjpVObj vobj = null; Statement stmt = null; Connection conn = null; try (conn = DriverManager.getConnection ( "proxool.Access"); stmt = conn.createStatement (); ResultSet rs = stmt.executeQuery ( "select * from examination3 where id =" + a [i]); while (rs.next ()) (int id = rs.getInt ( "id"); String title = rs.getString ( "content"); String content = rs.getString (the "option") ; String explain = rs.getString ( "explain"); int test_type = rs.getInt ( "test_type"); String answer = rs.getString (the "answer"); int score = rs.getInt (the "score"); Date qdate = rs.getDate ( "qdate"); vobj = new ScjpVObj (id, title, content, explain, test_type, answer, score, qdate); if (vobj! = null) (scjpCache.put ( "ScjpVObj" + i , vobj); / / cache the questions))) catch (SQLException e) (System.err.println (e.getMessage ());) catch (Exception e) (System.err.println (e.getMessage () );) finally (try (stmt.close (); conn.close ();) catch (SQLException ex1) (System.out.print (ex1);)) return vobj;))
3, JSP pages
<% @ Page contentType = "text / html; gb2312 charset ="%>
<% @ Page language = "java"%>
<% @ Page import = "com.java3z.data .*"%>
<%
ScjpVObjManager cache = ScjpVObjManager.getInstance ();
Int a [] = new int [300];
For (int i = 0; i <300; i + +)
A [i] = i;
For (int i = 0; i <300; i + +) (/ / cache memory will be the test for chaos
Int j = (int) (Math.random () * 300);
Int temp = a [i];
A [i] = a [j];
A [j] = temp;
)
For (int count = 0; count <60; count ++){// out that 60
ScjpVObj bv = (ScjpVObj) cache.getScjpVObj (a [count], true);
String content = bv.getContent ();
Out.println (content + "
");
)
%>
Fourth, if inappropriate, to please correct me.
Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr>
↑ Back
Tags: scjp






