Skip to main content


Showing posts from February, 2011

How to use the jasper report scriptletClass

1. define the class extends to JRDefaultScriptlet
public class ReportScriptlet extends net.sf.jasperreports.engine.JRDefaultScriptlet
  // format of strDate: YYYY/MM/DD
public static String getFormatedDate(String strDate,String outputFormat){
try {
        // Some examples
        SimpleDateFormat formatter = new SimpleDateFormat(INPUT_DATE_FORMAT);
        Date date = (Date)formatter.parse(strDate.trim());
        String formatedDate = formatter.format(date);
        System.out.println("formatedDate:" + formatedDate);
return formatedDate;
    }catch (Exception e) {

return strDate; // just don't format the String
2. Added scriptletClass="tnReports.ReportScriptlet" in the report definition file(.jrxml)
3. Use the method defined in the class,e.g.
 $P{REPORT_SCRIPTLET}.getFormatedDate((String)$P{REPORT_SCRIPTLET}.getParameterValue("START_DATE"),"MMM dd, yyyy")

Java Date and Time Patterns

Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') to avoid interpretation."''" represents a single quote. All other characters are not interpreted; they're simply copied into the output string during formatting or matched against the input string during parsing.
The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):
LetterDate or Time ComponentPresentationExamplesGEra designatorTextADyYearYear1996; 96MMonth in yearMonthJuly; Jul; 07wWeek in yearNumber27WWeek in monthNumber2DDay in yearNumber189dDay in monthNumber10FDay of week in monthNumber2EDay in weekTextTuesday; TueaAm/pm markerTextPMHHour in day…
first : update or create smb.conf under linux

vim /etc/samba/smb.conf

#============================ Share Definitions ==============================

        comment = Home Directories
        browseable = yes
        writable = yes
        path = /usr/local
;       valid users = %S
;       valid users = MYDOMAIN\%S

        comment = All Printers
        path = /var/spool/samba
        browseable = no
        guest ok = no
        writable = no
        printable = yes
# ===== end =============

second:  add smb user:

smbpasswd -a root

third: restart smb service

/etc/init.d/smb restart

Shallow and retained sizes

YourKit Java Profiler is capable of measuringshallowandretainedsizes of objects.
Shallow size of an object is the amount of memory allocated to store the object itself, not taking into account the referenced objects. Shallow size of a regular (non-array) object depends on the number and types of its fields. Shallow size of an array depends on the array length and the type of its elements (objects, primitive types). Shallow size of a set of objects represents the sum of shallow sizes of all objects in the set. Retained size of an object is its shallow size plus the shallow sizes of the objects that are accessible, directly or indirectly, only from this object. In other words, the retained size represents the amount of memory that will be freed by the garbage collector when this object is collected. To better understand the notion of the retained size, let us look at the following examples: In order to measure the retained sizes, all objects in memory are treated as nodes of a graph where…

Frequently Asked Questions about Garbage Collection

Frequently Asked Questions
about Garbage Collection
in the HotspotTM JavaTM Virtual Machine This document describes the behavior of the Java(tm) HotSpot(tm) virtual machine. This behavior is not part of the VM specification, however, and is subject to change in future releases. Moreover the behavior described here is generic behavior and will not apply to the execution of all Java applications.
How is the generational collector implemented in HotSpot(tm)?
The default collector in HotSpot has two generations: the young generation and the tenured generation. Most allocations are done in the young generation. The young generation is optimized for objects that have a short lifetime relative to the interval between collections. Objects that survive several collections in the young generation are moved to the tenured generation. The young generation is typically smaller and is collected more often. The tenured generation is typically larger and collected less often.
The young generation coll…

Live - solving the jasper report out of memory and high cpu usage problems

I still can not find the solution. So I summary all the things and tell my boss about it. If any one knows the solution, please let me know.

Symptom: 1.The JVM became Out of memory when creating big consumption report 2.Those JRTemplateElement-instances is still there occupied even if I logged out the system
Reason:         1. There is a large number of JRTemplateElement-instances cached in the memory 2.The clearobjects() method in ReportThread class has not been triggered when logging out
Action I tried:      About the Virtualizer: 1.Replacing the JRSwapFileVirtualizer with JRFileVirtualizer 2.Not use any FileVirtualizer for cache the report in the hard disk Result: The japserreport still creating the a large number of JRTemplateElement-instances in the memory     About the work around below,      I tried: item 3(in below work around list) – result: it helps to reduce  the size of the JRTemplateElement Object                Item 4,5 – result : it helps a lot to reduce the number of  JRTemplateE…