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

JMeter example source code file (DOMPool.java)

This example JMeter source code file (DOMPool.java) 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.

Java - JMeter tags/keywords

concurrenthashmap, concurrenthashmap, document, document, dom, dompool, dompool, map, map, memcache, threading, threads, util

The JMeter DOMPool.java source code

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.Map;
import java.util.concurrent.ConcurrentHashMap;

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.
 * <p>
 * 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.
 * <p>
 * Created on: Jun 17, 2003<br>
 *
 */
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.
     */
    private static final Map<Object, Document> MEMCACHE = new ConcurrentHashMap(50);

    /**
     * Return a document.
     *
     * @param key
     * @return Document
     */
    public static Document getDocument(Object key) {
        return MEMCACHE.get(key);
    }

    /**
     * Add an object to the cache.
     *
     * @param key
     * @param data
     */
    public static void putDocument(Object key, Document data) {
        MEMCACHE.put(key, data);
    }

    /**
     * Private constructor to prevent instantiation.
     */
    private DOMPool() {
    }
}

Other JMeter examples (source code examples)

Here is a short list of links related to this JMeter DOMPool.java source code file:

... 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.