Minimizing memory Leaks in your java j2ee applications | Techartifact

Enough of ADF.Lets talk about memory leak in java today in our application.How we can reduce it.

Java’s memory managmement (i.e Garbage collectionGarbage collection -how it works) prevents lost references and dangling references but it is still possibilities to create memory leaks in other ways. If the application run with memory leaks for long duration ,you will get the error java.lang.OutOfMemoryError.

In java ,typically the memory leak occur when an object of a longer lifecycle has references to the objects of a short life cycle. This prevents the
object with short life cycle being garbage collected. The developer must remember to remove the references to the short lived object from the long-lived objects.Objects with same life cycle do not cause any problem because the garbage collector is smart enough to deal with the circular references.

-> Java collection class like HashTable, ArrayList etc maintain references to other objects.So having a long life cycle ArrayList pointing to many . . short-lifecyle objects can cause memory leaks.

-> Commonly used singleton Design pattern can cause memory leaks.Singleton typically have a long lifecycle. If a singleton has an arrayList or a HashTable then there is potential for memory leaks.

-> Java Programming language includes a finalize method that allows an object to free system resources ,in other words to clean up after itself. However using finalize doesn’t guarantee that a class will clean up resources expediently. A better approach for cleaning up resources involves the finally method and an explicit close statement.so freeing up the valuable resources in the finalize method or try {} block instead of finally() block can cause memory leaks.

Exporting table data into Excel File in ADF

Here’s the quickest way of exporting table data into Excel File :

1) Create Model using Business Components and refresh Data Controls.
2) Create a standard and JSF page and drag-drop the control the data control to create a ADF table. Name the ID of the table as t1.
3) Create a Command Button and change the text to “Export”.
4) Refer to the snapshot below :

5) Drag-Drop Export Collection Action Listener onto the Command Button “Export”.
6) Set the following Configurations for bindings :

ExportedId : t1
Type : excelHTML

7) Set the Filename and Title in the property inspector of Export Collection Action Listener.
8) Run the page.

Author- Ankit Gupta

happy coding with Techartifact.

get object of ApplicationModule in managed bean in ADF | Techartifact

Requirment- Need an object of Application module in managed bean

Sometime we required to get an object of ApplicationModule in managed bean.May be we want to play with some VO object which we can get from
ApplicationModuleImpl Object only.

There are two ways.

First way-

        FacesContext context = FacesContext.getCurrentInstance();
        BindingContext bindingContext = BindingContext.getCurrent();
        DCDataControl dc  = bindingContext.findDataControl("AppModuleAMDataControl"); // Name of application module in datacontrolBinding.cpx
        AppModuleAMImpl appM = (AppModuleAMImpl)dc.getDataProvider();
     

Above AppModuleAMDataControl is name of application module in datacontrolBinding.cpx,open datacontrol and check the ID in tag. See below for reference.

 <BC4JDataControl id="AppModuleAMDataControl" Package="oper.model.module"
                     FactoryClass="oracle.adf.model.bc4j.DataControlFactoryImpl" SupportsTransactions="true"
                     SupportsFindMode="true" SupportsRangesize="true" SupportsResetState="true"
                     SupportsSortCollection="true" Configuration="AppModuleAMLocalWeb" syncMode="Immediate"
                     xmlns="http://xmlns.oracle.com/adfm/datacontrol"/>

Now you got the application module you can get the object of any ViewObjectImpl.

Second Way-

You can get the object of applicationModuleImpl by writing this line-

AppModuleAMImpl am = (AppModuleAMImpl)resolvElDC(AppModuleAMDataControl)

resolvElDC method is described below


private Object resolvElDC(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp =
            elFactory.createValueExpression(elContext, #{data. + data + .dataProvider}, Object.class);
        return valueExp.getValue(elContext);
    }

Happy coding with Techartifact . 🙂