Tuning Garbage collection with the 1.4.2 Hotspot JVM

  • For many applications garbage collection performance is not significant
  • Default collector should be first choice
There are essentially two GC threads running. One is a very lightweight thread which does "little" collections primarily on the Eden (a.k.a. Young) generation of the heap. The other is the Full GC thread which traverses the entire heap when there is not enough memory left to allocate space for objects which get promoted from the Eden to the older generation(s).
If there is a memory leak or inadequate heap allocated, eventually the older generation will start to run out of room causing the Full GC thread to run (nearly) continuously. Since this process "stops the world", Resin won't be able to respond to requests and they'll start to back up.
Read More on Tuning Garbage collection with the 1.4.2 Hotspot JVM

DB/DBM configuration in DB2 on Z/OS, OS/390 or AS/400

Question:
I could connect to DB2 database on AS/400, but cannot> see any DBM or DB configuration. Is database or database manager> configuration available for DB2 on Z/OS, OS/390 or AS/400?
Solution:
Most of the config parms for DB2 for z/OS are in the zparms. The zparms arenot closely related to either the db or dbm configuration parms on DB2 forLinux, UNIX, and Windows. Usually only the DB2 systems programmer (not theDBA) can change the zparms.

How to Automate the process of importing file from IBM Mainframes to spreedsheet

Scenario:
I have a TAB Delimited and it contain 10 fields., and Presently this is downloading into testfile.txt importing into excel spreedsheet.
Now, I need to automate this process. by writing a program which sends this file to Spreadsheet.


Solution:
A spreadsheet is not a mainframe entity, so can not be created on the mainframe.

As far as I can remember, this could not be done by a mainframe process, and that the current way that this task is currently being performed is the only way.


Read More on this artcile from IBM Mainfarmes Forums

JCL to unzip the file zipped in unix by using gzip

Question:

Can Someone let me know how to ZIP file from UNIX system and UNZIP in Mainframes.
We have PKZIP in our system os/390
Can any one have the JCL to unzip the file zipped in unix by using gzip. 


Solution:


gunzip and gzip typically work under Unix System Services (USS) on USS files.
If you're asking for specific JCL to run PKZIP against your file, shouldn't you contact your site support group or the PKZIP vendor for assistance and/or the manual? The precise JCL will be site-dependent and may vary depending on how and where PKZIP was installed. 

How to convert File from UNIX to IBM Mainframes using PKZIP in os/390?

Question : We have a ZIP file in the Unix System and want to UNZIP it in the mainframes.

Solution:

The previous versions of PKZIP have supported GZIP, so I have to believe that the newest versions do also.

just downloaded a copy of the PKZIP for z/OS Version 9 User's Guide, and Chapter 12 is actually titled Processing with GZIP.

According to the manual, you need to specify:

-ARCHIVE_ZIPFORMAT(GZIP)

and has a few notes:

The GZIP standard does not support PKWARE archive attributes; therefore, some
SecureZIP features are not available for use when the GZIP format is enabled. Some
features which are excluded from use are: strong encryption, digital signatures,
multiple files per GZIP stream, self-extracting archives.
• When enabled with GZIP, password-based 96-bit encryption is supported for decryption
under PKZIP for MVS, PKZIP for zSeries, PKZIP for OS/400, PKZIP for i5/OS,
SecureZIP for i5/OS, PKZIP for z/OS, and SecureZIP for z/OS.
• When processing input GZIP archives, see also: GZIP_SUFFIX and GZIPCRC_IGNORE

How can I recursively grep through sub-directories ? | Unix Tutorial |Linux / UNIX Recursively Search All Files For A String

Question :How do i recursively grep (search text files) in unix?

For example, if i want to find the word "hello" in a unix directory /tmp and all its subdirectories in the .log files?  i want the file name, file path, and line number with context.


Solution:


find /tmp -name \*.log -exec grep pall {} \; -exec ls -l {} \;

The find command you probably know. It searches for files or directorys where you want him to search and to what pattern to match.

So :
"find /tmp" says only start searching in /tmp
"-name \*.log" says to look for all files or directory ending with "log" the \ before the star says to not look for a file or directory named "*log" but to make it a pattern
"-exec grep pall {} \;" says that the result of find in /tmp with the pattern ending on "log" should do the following : "grep hello /tmp/script" so {} \; is replaced with the current result. It's hard to explain the syntax, I think you should just take this as it is and copy the syntax when you need it
"-exec ls -l {} \;" has the same syntax and executes the ls -l command for the current result. If you don't do this last -exec you don't know what file he grep the text from.

How to Create a Blank DOM Document | Java DOM Tutorial complete guide to DOM

This tutorial shows you how to create blank DOM document.
JAXP is a Java interface that provides Parsing XML documents.
The class DocumentBuilderFactory is responsible for creating new DOM parsers. Normally it is used to a DOM parser.
Creating an Empty DOM Document

public static Document createDomDocument() {
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.newDocument();
        return doc;
    } catch (ParserConfigurationException e) {
    }
    return null;
}
Explanation:
DocumentBuilder builder = Factory.newDocumentBuilder():- This method creates a DocumentBuilder object with the help of a DocumentBuilderFactory
Document doc = builder.newDocument():- This method obtain a new instance of a DOM Document object to build a DOM tree.

XML,XML Tutorials,XML Examples,XML Example,Java DOM Tutorial

What is DOM?

The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated. In the DOM specification, the term "document" is used in the broad sense - increasingly, XML is being used as a way of representing many different kinds of information that may be stored in diverse systems, and much of this would traditionally be seen as data rather than as documents. Nevertheless, XML presents this data as documents, and the DOM may be used to manage this data.

The DOM is an interface that exposes an XML document as a tree structure comprised of nodes. The DOM allows you to programmatically navigate the tree and add, change and delete any of its elements.

XML and Java Parsing XML using Java Tutorial

SAX parser is a Event Driven Parser. You provide the callback methods, and the parser invokes them as it reads the XML data. Finally, you can't "back up" to an earlier part of the document, or rearrange it, any more than you can back up a serial data stream or rearrange characters you have read from that stream. The following Packages need to be imported in your Java File to use the SAX parser.
import java.io.*;
import org.xml.sax.*;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

public class BooksLibrary extends HandlerBase
{
...
}
Next Let's declare the Main method and also setup the Parser
public static void main (String argv [])
{
  SAXParserFactory factory = SAXParserFactory.newInstance();
  try {

        out = new OutputStreamWriter (System.out, "UTF8");
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse( new File(XML_FILE_NAME), new BooksLibrary() );

  } catch (Throwable err) {
        err.printStackTrace ();
  }
}
As seen above first we get a new instance of SAXParserFactory and from this one we create a new Instance of SaxParser. To the Parse Method of SaxParser, we pass two parameters, name of the XML File and the class which implements interface HandlerBase
Currently in our Code, the same JavaFile, BooksLibrary.java implements interface HandlerBase.
Note:
    The javax.xml.parsers.SAXParser class is a wrapper that defines a number of convenience methods. It wraps the org.xml.sax.Parser object. If needed, you can obtain that parser using the SAXParser's getParser() method.
The Following Methods needs to be implemented from the DocumentHandlerBase Interface, and Description above each methods explains when this Method is called. These Methods are called automatically while parsing the XML file and when the corresponding data element is reached. Please refer to the attached Java Source File  to see how these methods are implemented. When you run this Program the output will clearly show When a attribute is reached and when a Element is reached and how each of these methods are called.

Parsing / Reading XML file in Java Using org.w3c.dom parser

I have a Piece of code which can be used to Parse a XML file using java DOM Parser.

Step 1: Create a XML file as below

<?xml version="1.0"?>
<Employees>
    <Employee>
        <name>Melvyn</name>
        <grade>B</grade>
        <age>23</age>
    </Employee>
    <Employee>
        <name>Nixon</name>
        <grade>A</grade>
        <age>25</age>
    </Employee>
    <Employee>
        <name>Bruce</name>
        <grade>A</grade>
        <age>28</age>
    </Employee>
</Employees>

2.Java Code to Read the XML file

package net.viralpatel.java.xmlparser;
 
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
 
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
 
public class XMLParser {
 
    public void getAllUserNames(String fileName) {
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            File file = new File(fileName);
            if (file.exists()) {
                Document doc = db.parse(file);
                Element docEle = doc.getDocumentElement();
 
                // Print root element of the document
                System.out.println("Root element of the document: "
                        + docEle.getNodeName());
 
                NodeList EmployeeList = docEle.getElementsByTagName("Employee");
 
                // Print total Employee elements in document
                System.out
                        .println("Total Employees: " + EmployeeList.getLength());
 
                if (EmployeeList != null && EmployeeList.getLength() > 0) {
                    for (int i = 0; i < EmployeeList.getLength(); i++) {
 
                        Node node = EmployeeList.item(i);
 
                        if (node.getNodeType() == Node.ELEMENT_NODE) {
 
                            System.out
                                    .println("=====================");
 
                            Element e = (Element) node;
                            NodeList nodeList = e.getElementsByTagName("name");
                            System.out.println("Name: "
                                    + nodeList.item(0).getChildNodes().item(0)
                                            .getNodeValue());
 
                            nodeList = e.getElementsByTagName("grade");
                            System.out.println("Grade: "
                                    + nodeList.item(0).getChildNodes().item(0)
                                            .getNodeValue());
 
                            nodeList = e.getElementsByTagName("age");
                            System.out.println("Age: "
                                    + nodeList.item(0).getChildNodes().item(0)
                                            .getNodeValue());
                        }
                    }
                } else {
                    System.exit(1);
                }
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
    public static void main(String[] args) {
 
        XMLParser parser = new XMLParser();
        parser.getAllUserNames("c:\\test.xml");
    }
}

Following is the output of our XML parser.
Program Output

Root element of the document: students
Total Employees: 3
==============================
Name: Melvyn
Grade: B
Age: 23
==============================
Name: Nixon
Grade: A
Age: 25
==============================
Name: Bruce
Grade: A
Age: 28

How to read XML file in Java using DOM Parser

Here’s an example to demonstrate how to read a XML file in Java with DOM parser. The DOM interface is the easiest to understand. It parses an entire XML document and load it into memory, modeling it with Object for the traversal.

Step 1:Create a XML File

<?xml version="1.0"?>
<company>
    <Employee>
        <firstname>yong</firstname>
        <lastname>mook kim</lastname>
        <nickname>mkyong</nickname>
        <salary>100000</salary>
    </Employee>
    <Employee>
        <firstname>low</firstname>
        <lastname>yin fong</lastname>
        <nickname>fong fong</nickname>
        <salary>200000</salary>
    </Employee>
</company>

2.Create a Java File to Process this XML file

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;

public class ReadXMLFile {

 public static void main(String argv[]) {

 try {

    File fXmlFile = new File("c:\\file.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();

    System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
    NodeList nList = doc.getElementsByTagName("Employee");
    System.out.println("-----------------------");

    for (int temp = 0; temp < nList.getLength(); temp++) {

       Node nNode = nList.item(temp);      
       if (nNode.getNodeType() == Node.ELEMENT_NODE) {

          Element eElement = (Element) nNode;

          System.out.println("First Name : "  + getTagValue("firstname",eElement));
          System.out.println("Last Name : "  + getTagValue("lastname",eElement));
          System.out.println("Nick Name : "  + getTagValue("nickname",eElement));
          System.out.println("Salary : "  + getTagValue("salary",eElement));

        }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
 }

 private static String getTagValue(String sTag, Element eElement){
    NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
    Node nValue = (Node) nlList.item(0);

    return nValue.getNodeValue();   
 }

}

How to read XML file in Java using SAX Parser ?

SAX parser is work differently with DOM parser, it does not load any XML document into memory and create some object representation of the XML document. Instead, the SAX parser use callback function (org.xml.sax.helpers.DefaultHandler) to informs clients of the XML document structure.

Let’s start to see how to read a XML file with SAX parser.

1. Create a XML file

Create a simple XML file as following

<?xml version="1.0"?>
<company>
 <Employee>
  <firstname>yong</firstname>
  <lastname>mook kim</lastname>
  <nickname>mkyong</nickname>
  <salary>60000</salary>
 </Employee>
 <Employee>
  <firstname>low</firstname>
  <lastname>yin fong</lastname>
  <nickname>fong fong</nickname>
  <salary>30000</salary>
 </Employee>
</company>

2. Create a Java file

Use SAX parser to parse the XML file.

package com.mkyong.test;
 
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
 
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
 
public class ReadXMLFileSAX {
 
 public static void main(String argv[]) {
 
  try {
 
     SAXParserFactory factory = SAXParserFactory.newInstance();
     SAXParser saxParser = factory.newSAXParser();
 
     DefaultHandler handler = new DefaultHandler() {
 
     boolean bfname = false;
     boolean blname = false;
     boolean bnname = false;
     boolean bsalary = false;
 
     public void startElement(String uri, String localName,
        String qName, Attributes attributes)
        throws SAXException {
 
        System.out.println("Start Element :" + qName);
 
        if (qName.equalsIgnoreCase("FIRSTNAME")) {
           bfname = true;
        }
 
        if (qName.equalsIgnoreCase("LASTNAME")) {
           blname = true;
        }
 
        if (qName.equalsIgnoreCase("NICKNAME")) {
           bnname = true;
        }
 
        if (qName.equalsIgnoreCase("SALARY")) {
           bsalary = true;
        }
 
     }
 
     public void endElement(String uri, String localName,
          String qName)
          throws SAXException {
 
          System.out.println("End Element :" + qName);
 
     }
 
     public void characters(char ch[], int start, int length)
         throws SAXException {
 
         if (bfname) {
            System.out.println("First Name : "
                + new String(ch, start, length));
            bfname = false;
          }
 
          if (blname) {
              System.out.println("Last Name : "
                  + new String(ch, start, length));
              blname = false;
           }
 
          if (bnname) {
              System.out.println("Nick Name : "
                  + new String(ch, start, length));
              bnname = false;
           }
 
          if (bsalary) {
              System.out.println("Salary : "
                  + new String(ch, start, length));
              bsalary = false;
           }
 
        }
 
      };
 
      saxParser.parse("c:\\file.xml", handler);
 
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 
}

  • startDocument() and endDocument() – methods called at the start and end of an XML document.
  • startElement() and endElement() – methods called at the start and end of a document element.
  • characters() – method called with the text contents in between the start and end tags of an XML document element.