Register | Log in | Password |

365 projects | 71 services | 215 websites | 1073 freelancers | 2763 topics | advertise


Purchase JoomlaWatch:
30 day money-back guarantee
Read more...
9 EUR lifetime license
Buy Now

15 EUR lifetime license
Buy Now
(nofollow link from sponsors page)

Login:

22.8%United States United States
15.5%India India
7.3%Russian Federation Russian Federation
6.9%Colombia Colombia
6.1%Germany Germany
5.1%United Kingdom United Kingdom
4.4%Poland Poland
3.4%Netherlands Netherlands
3%France France
2.8%Canada Canada

Today: 1359
Yesterday: 1639
This Week: 4584
Last Week: 10059
This Month: 11283
Total: 34597

Users

Most active users today from total of 66:
matto, rottenberg, billspo, crony, Adelavigne, dwlamb, dontbugmeplease, manuelflores, eghtedar, FreeMe, rockiesrider, Machin, michmich, speru, infomech, blombo, sunconcept, rtuszyns, Pedropedro, tegralens
About JoomlaWatch:
JoomlaWatch is popular joomla visitor tracking and live stats component. It provides several features such as spam blocking, goals tracking, charts, nightly email reports, latest visit map, interactive HTML5 traffic flow graph and many other useful functionalities, which will help you to optimize your site.
RSS Feeds:

rss Freelance
rss Projects
rss Forum
rss Resources

Home

Java Data Repository performance

Scenario:
It’s a common scenario that a web site rarely updates the background database but frequently
access the database to fetch requested data. Consider the web site that provides the results of Secondary School Certificate exam of a country, based the population of that country the total number of students who attended the exam may be 2 million, 3 million or more. In India it may be more than 10 million. When the result is just published just think about the number of hits per second on that web site. A student just provides a Student Registration number and gets the result from the site. So should that
web application search the database every time there is a request for result in that site? To me it’s a
‘NO’. In the age of WiMax and 3G it is expected the website to appear in a twinkling of an eye. So if you
can provide sufficient RAM to that web server why don’t you use data repository. “Data
Repository”? Yes. Data Repository: It’s an implementation of virtual storage of a portion of a database or entire database.

The concept is:
Database (MySQL, SQL Server etc), Load the data in to RAM and refresh periodically Æ Response
of the data query. For each subsequent database query, after the initial loading, the response is generated from the data loaded into RAM. So, there is no need to knock the database for every query. This is a quite
faster approach. But remember if the database rarely has insert, update and delete operation this
approach is very much efficient. If the there is a change in the database the change will be reflected in the database only after the data repository is refreshed.

Implementation:
So in a web server how would you implement that? Here is an example to implement Data
Repository using Java and STRUTS framework. For simplicity I have omitted some minor parts such as
import statement, portion to fetch data from Database in the reload() method. I have also omitted
the details of the DataDTO class.

 

Implementing the DataRepository:

/*********************** Start of DataRepository.java************************/ 
public class DataRepository 
{ 
	// 60 Seconds, you can change it s u like   
  public static final long REFRESH_INTERVAL = 60 * 1000; 
  static DataRepository repository = null; 
  private long lastRelodingTime; 
  //Its a map to get Result using Registration number as KEY 
  HashMap regMap; 
  private DataRepository()  { 
    forceReload(); 
  } 
  public static DataRepository getInstance()  { 
    if (repository == null) 
      createDataRepository(); 
    return repository; 
  } 
 
  private synchronized static void createDataRepository()  { 
    if (repository == null) 
      repository = new DataRepository(); 
  } 
  private void reload()  { 
   // DataDTO is the clas to hold Registration Number,  
   // Name and CGPA of any student 
   // For simplicity here I havent added it. 
      ResultSet rs = null; 
      rs = ResultSet after database query 
   while(rs.next()) 
   {  
    // DataDTO provides StudentName, Student Registration Number 
    // and student CGPA. You can add additional member variable 
    // or method for more details*/ 
    DataDTO dto = new DataDTO();  
    dto.setName(rs.getString("name")); 
    dto.setCGPA(rs.getFloat("cgpa")); 
    regMap.put(dto, new Long(rs.getLong("registration")));  
   } 
     
  } 
  public synchronized DataDTO getResult(long registrationNumber)  { 
    checkForReload(); 
    return (DataDTO)this.regMap.get(new Long(registrationNumber)); 
  } 
  private void checkForReload()  { 
    long now = System.currentTimeMillis(); 
    if (now - lastRelodingTime > REFRESH_INTERVAL) { 
      lastRelodingTime = now; 
      reload(); 
   } 
  } 
  public synchronized void forceReload()  { 
    lastRelodingTime = System.currentTimeMillis(); 
    reload(); 
  } 
}/*********************** End of DataRepository.java************************/ 

Look at the implementation, you can’t directly create object of the DataRepository Class. The
DataRepository class is an implementation of a singleton. So, there will be only one instance of the
DataRepository Class.
You should get the instance of the Class this way:
DataRepository instance = DataRepository.getInstance();

The logic here is, you create a single instance of the class. Load the data from database to Java data
structure inside the reload() method. The data loaded from the database is refreshed when a new
request is made and the refresh time interval expires. Now the object of the DataRepository Class is
loaded into the memory along with the data loaded from Database.
Suppose, a student with registration number = 101 is looking for his result. You can provide the
result without searching it again.
DataDTO studentInfo ;
long regNumber = 101;
studentInfo=(DataDTO) DataRepository.getInstance().getResult(regNumber);
String studentName = studentInfo.getName();
float studentCGPA = studentInfo.getCGPA();

If you are using STRUTS framework you can have Form Class that extends ActionForm. Say, you Form
class name is DataForm.
DataForm form = new DataForm();
form.setName(studentName)
form.setCGPA(studentCGPA)
Finally: Forward this DataForm to your Action class.
You can use this architecture in any desktop, web or other server type application based on your
requirements.

 

Add comment


Security code
Refresh


no license? questions?

Recommended: (advertise)
Joomlawatch 1.2.17 Demo (PRO: 9/15 EUR)
Download Joomlawatch 1.2.17 (PRO: 9/15 EUR)



Rate this extension ...


Stay in touch:

New online JoomlaWatch demo available here: (link)
12 hours ago from web

New comprehensive article on JoomlaWatch goals: (link)

JoomlaWatch is now available for Drupal as unlocked BETA version for testing: (link)
3 days ago from web

New article about JoomlaWatch Live Stats feature: (link)
5 days ago from web

Tested versions 1.2.12 FREE, 1.2.17 PRO, 1.2.18 BETA on Joomla 2.5 and older Joomla 1.5 - confirmed to work on both Joomla versions
2 weeks ago from web

Small installer fixes - added JoomlaWatch compatibility with Joomla 2.5
2 weeks ago from web

New article on JoomlaWatch Traffic Flow feature: (link) ... All features of JoomlaWatch will be documented this way.
2 weeks ago from web

Another minor fixes for version 1.2.17 and 1.2.18, added functionality to display only changed values in SEO report - important keyprases
2 weeks ago from web

Minor fixes for JoomlaWatch version 1.2.17 (language files), you can find the latest package in customer zone ((link)
3 weeks ago from web

If you'd like to help with testing of the latest 1.2.18 BETA with new features (Joomla/Wordpress),please add me on skype: matto3c.Thank you!

New article on JoomlaWatch SEO (Search Engine Optimization) report functionality - (link)

JoomlaWatch 1.2.18 is out now! Features new click heatmap feature, SEO report - how people find you on google, and many other improvements

Reorganized the menu items. Now you'll be able to easily find most requested links

JoomlaWatch 1.2.18 BETA now ready! Main features: - Heatmap integration - SEO reports - Anti-spam section visualization (link)

Fixed one issue: no unique visits recorded; PHP $_SERVER['REMOTE_ADDR'] doesn't always return remote IP address! using HTTP_X_FORWARDED_FOR

Christmas Special - 19% OFF from all licenses until 25th of December 2011

JoomlaWatch Heatmap functionality nearly done. Works with all client resolutions. Will be available in next version. (link)

Simple customer zone - (link) is now ready. Users who purchased the PRO version can now download newest version from there.

Because of the problems with payments and forwarding. We are using (link) service to deliver you the files after purchase.

Tracking Expenses from SMS android application is now published on android market :) and it's completely free !



Partners:
Freelance ColdFusion, Flex, PHP

Olejomalby, abstraktne obrazy

Camping Europe

WinAsm Studio

Vyšné Ružbachy

Sochy, Reštaurovanie

R.E.M.

Valid XHTML 1.0 Transitional

RSS feed:

Statistics:
Search Engine Genie Promotion Widget
Privacy policy | Advertise | Donate

Locations of visitors to this page


©2003-2010 Codegravity.com