alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

// $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/DOMPool.java,v 1.5 2004/02/12 00:29:49 sebb Exp $
/*
 * Copyright 2003-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
*/

package org.apache.jmeter.protocol.http.util;

import java.util.HashMap;
import org.w3c.dom.Document;

/**
 * The purpose of this class is to cache the DOM Documents in memory and
 * by-pass parsing. For old systems or laptops, it's not practical to parse the
 * XML documents every time. Therefore using a memory cache can reduce the CPU
 * usage.
 * 

* For now this is a simple version to test the feasibility of caching. If it * works, this class will be replaced with an Apache commons or something * equivalent. If I was familiar with Apache Commons Pool, I would probably * use it, but since I don't know the API, it is quicker for Proof of Concept * to just write a dumb one. If the number documents in the pool exceed several * hundred, it will take a long time for the lookup. *

* Created on: Jun 17, 2003
* * @author Peter Lin * @version $Revision: 1.5 $ */ public final class DOMPool { /** * The cache is created with an initial size of 50. Running a webservice * test on an old system will likely run into memory or CPU problems long * before the HashMap is an issue. */ protected static HashMap MEMCACHE = new HashMap(50); /** * Return a document. * @param key * @return Document */ public static Document getDocument(Object key) { return (Document) MEMCACHE.get(key); } /** * Add an object to the cache. * @param key * @param data */ public static void putDocument(Object key, Object data) { MEMCACHE.put(key, data); } /** * Private constructor to prevent instantiation. */ private DOMPool() { } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.