Tag Archives: java

Hugepages and Java

As a data point, at a previous employer we played a little with the use of HugePages and memory mapped files in an attempt to get better performance.
Java’s support for the use of HugePages is on a best effort basis and our experimentation found that java was initially using the HugePages, but over time (a few hours), the HugePages were no longer used by the JVM—thus effectively reducing the available amount of RAM by the amount allocated for HugePages. We ended up disabling HugePages for our usage. I do not recall any concern/investigation about the Anonymous huge pages.
 
In the above case, however, we were constantly changing the memmapped files (these were large image files), since each request would access different image files, and the files were accessed over network storage.
Advertisements

Leave a comment

Filed under JVM, Linux

How do I split a string with any whitespace chars as delimiters?

in short use : myString.split("\\s+");

details in Stack Overflow

Leave a comment

Filed under Java

How-to Parse an XML string in Java

Found this simple but elegant solution on the web, i am listing it here for my record, but you can also find it here – http://www.rgagnon.com/javadetails/java-0573.html

import javax.xml.parsers.*;
import org.xml.sax.InputSource;
import org.w3c.dom.*;
import java.io.*;

public class ParseXMLString {

public static void main(String arg[]) {
String xmlRecords =
“” +
” ” +
” John” +
” Manager” +
” ” +
” ” +
” Sara” +
” Clerk” +
” ” +
“”;

try {
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xmlRecords));

Document doc = db.parse(is);
NodeList nodes = doc.getElementsByTagName(“employee”);

// iterate the employees
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);

NodeList name = element.getElementsByTagName(“name”);
Element line = (Element) name.item(0);
System.out.println(“Name: ” + getCharacterDataFromElement(line));

NodeList title = element.getElementsByTagName(“title”);
line = (Element) title.item(0);
System.out.println(“Title: ” + getCharacterDataFromElement(line));
}
}
catch (Exception e) {
e.printStackTrace();
}
/*
output :
Name: John
Title: Manager
Name: Sara
Title: Clerk
*/

}

public static String getCharacterDataFromElement(Element e) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
}
return “?”;
}
}

Leave a comment

Filed under Java, XML