Thursday, August 22, 2013

Ubuntu 12.04 64bit Kernel freeze on dual VGA

I had Ubuntu 12.04 (3.2.0-45) 64bit installed on a Dell laptop. The kernel used to freeze very frequently on a daily basis. Followed various posts and kept apt-get up to date but did not fix the issue. I could not narrow it down by the actual cause of the issue by analyzing the system logs. So I was reluctant to re-install the OS and verify as there is no guarantee that the problem will not re-appear.
However by absorbing the various freeze scenarios it boiled down to whenever I was using more to do with graphics drivers from the application. So I did the following steps and it did not freeze after that, it's been more than a week and it did not freeze even once, though its not an actual fix and but this work around greatly works for me.

1. lspci | grep VGA - confirmed that I had two video drivers (Intel and Nvidia)
2. But Nvidia was not active and I could not successfully install the Nvidia driver while Intel one is active.
3. So by disabling the "Optimus" in BIOS settings, I booted with recovery mode, and installed the Nvidia recommended drivers through Additional Drivers setting. When it's using with Intel driver the Nvidia drivers may not be listed through Additional Drivers setting and also apt-get install current-nvidia did not work for me. So I had to run it with low graphics mode so that I could successfully install the Nvidia driver.
4. Once the Nvidia driver is successfully installed and I re-booted the laptop without Intel VGA and Ubuntu sees only the Nvidia driver (so lspci | grep VGA shows only one driver) and that's all I had to do to overcome my kernel freeze issue!!!
5. This has one side effect of not being able to connect with dual external monitors but only one additional monitor works for me than living with freezing problem!

Monday, February 18, 2013

Struts multipart upload Java heap space OutOfMemoryError

I have seen following java heap OOM error in struts 1.x library. The below stack trace does not contain the any of the application specific code, so it's little difficult to pin point or debug where exactly in the code the issue got originated. 

java.lang.OutOfMemoryError: Java heap space
    java.io.ByteArrayOutputStream.(ByteArrayOutputStream.java:60)
    org.apache.commons.fileupload.DeferredFileOutputStream.(DeferredFileOutputStream.java:131)
    org.apache.commons.fileupload.DefaultFileItem.getOutputStream(DefaultFileItem.java:558)
    org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:406)
 org.apache.struts.upload.CommonsMultipartRequestHandler.handleRequest(CommonsMultipartRequestHandler.java:193)
    org.apache.struts.util.RequestUtils.populate(RequestUtils.java:443)
    org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:804)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 

Since I knew how to reproduce this error, I have fair understanding on which JSP page causing this error. So I took the heap dump (using -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath) and reproduced the error. And when I ran the heapdump bin file with JHAT server, I saw that there are many DeferredFileOutputStream objects created, which potentially causing the OOM error. I tried to locate this object in http://localhost:7000/class/0x31738c98 and I saw many instances...

 Class 0x31738c98
class org.apache.commons.fileupload.DeferredFileOutputStream
org.apache.commons.fileupload.DeferredFileOutputStream@0x140719b0 (37 bytes) : ??
org.apache.commons.fileupload.DeferredFileOutputStream@0x14ef8af8 (37 bytes) : ??
org.apache.commons.fileupload.DeferredFileOutputStream@0x240a4508 (37 bytes) : ??
org.apache.commons.fileupload.DeferredFileOutputStream@0x1e20a800 (37 bytes) : ??
org.apache.commons.fileupload.DeferredFileOutputStream@0x225969a8 (37 bytes) : ??
org.apache.commons.fileupload.DeferredFileOutputStream@0x161cb350 (37 bytes) : ??
org.apache.commons.fileupload.DeferredFileOutputStream@0x15cbf658 (37 bytes) : ??
org.apache.commons.fileupload.DeferredFileOutputStream@0x161cb5d0 (37 bytes) : ??
org.apache.commons.fileupload.DeferredFileOutputStream@0x161c9550 (37 bytes) : ??

Still I haven't gone into the source code of struts or apache library to figure out the actual root cause but I managed to identify the cause within the JSP file. 

Following line in the JSP file causing this issue.

html:form action='costCode' method='post' enctype='multipart/form-data'

Though there was no file upload functionality within this JSP, it's trying to send many options/checked selections data (100's of them) to action servlet. So by removing the enctype="multipart/form-data" attribute from the above tag the OOM got fixed!.


Monday, February 11, 2013

Real time shared drawing using Node.js and Socket.IO

Wednesday, February 6, 2013

Linked List Reverse circular way

Following code attempts to reverse a singly linked list in a circular fashion, for example, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7  to 7 -> 1 -> 6 -> 2 -> 5 -> 3 -> 4


There are other ways to achieve this output in much efficient way but I just thought of posting this naive one O(n * n).

public void reverseSpecial(Node node) {
        Node temp = node;
        Node endbefore = null;
        Node head = temp;
        Node newstart = null;
        while (head != null && head.next != null) {
            while (temp != null && temp.next != null) {
                endbefore = temp;
                temp = temp.next;
            }
            if (newstart == null) { //first time
                newstart = temp;
            }
            temp.next = head;
            temp = head.next;
            head.next = endbefore;
            head = temp;
            endbefore.next = null;
        }

Tuesday, November 20, 2012

Library not found: tibrvj

if you come across the below exception while connecting to Tibco RV then you could try follow below steps if that helps.

Caused by: TibrvException[error=901,message=Library not found: tibrvj]
at com.tibco.tibrv.Tibrv.loadLib(Tibrv.java:449)


This  happens because of Tibrv.open(Tibrv.IMPL_NATIVE); line in tibrvj java API code

 1. This means it could not find tibrvj.dll (and its dependent dlls from classpath setting)
 2. Not sure why such dependency when a standalone Java code wanted to establish a connection with Tibco RV for sending & receiving messages.
 3. If you have the Tibco RV installed on the same m/c, well then you can point to the bin directory of the installation and give that location in PATH variable
 4. if you don't have that installed and you wanted to connect to remote Tibco RV (running on different m/c) then you could copy the whole bin folder from the installation package & keep it on the local m/c where you are running the Java client code and configure the PATH setting.
 5.  Finally, if you want to connect to remote Tibco RV, you could try configuring the TibrvRvdTransport object with below parameter and mention the remote host where the daemon is running.

String service ="7500";
String network="";
String daemon="hostname:7500";
transport = new TibrvRvdTransport(service,network,daemon);






Tuesday, December 20, 2011

Understanding scoped-proxy in spring framework

Let say there are two classes, namely SingletonBean and PrototypeBean class, where prototype bean reference is kept inside the singleton bean. And as the name suggests, SingletonBean is specified with "singleton" scope and "prototype" scope for PrototypeBean. Now if we access the singleton bean using the application context, it will create single instance all times. However if we access the prototype bean reference using the singleton bean reference it will also show single instance all times because it has been wrapped inside the singleton bean, which is an expected behaviour under singleton pattern scenario. But we specified the prototype scope in PrototypeBean and if we wanted to return a new PrototypeBean object every time when we access using the singleton reference(getPrototypeBean()) then we need to specify the prototype bean additionally using

or @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS) as annotation.

Following example -

@Component

@Scope(value="singleton")

public class SingletonBean {


@Autowired

private PrototypeBean prototypeBean;
/**

*

*/

public SingletonBean() {



}

public PrototypeBean getPrototypeBean()
{

return prototypeBean;

}

public void
setPrototypeBean(PrototypeBean prototypeBean) {


this.prototypeBean = prototypeBean;
}

}


@Component

@Scope(value="prototype",
proxyMode=ScopedProxyMode.TARGET_CLASS)


public class PrototypeBean {


/**

*

*/

public PrototypeBean() {



}


}


When we test these beans after wiring them in xml file (using component-scan), we
find below results -

SingletonBean singletonBean = (SingletonBean)container.getBean("singletonBean");
System.out.println("singleton instance :"+singletonBean); //container.bean.SingletonBean@2200d5
System.out.println("prototype instance :"+singletonBean.getPrototypeBean()); //container.bean.PrototypeBean@df1832

singletonBean = (SingletonBean)container.getBean("singletonBean");
System.out.println("singleton instance :"+singletonBean); //container.bean.SingletonBean@2200d5
System.out.println("prototype instance :"+singletonBean.getPrototypeBean());//container.bean.PrototypeBean@ad8659

Wednesday, March 3, 2010

JGroups

To implement fail-over operation in java application, you can easily use jgroups (www.jgroups.org) library. If your application is not a J2EE based architecture (basically EJB containers involved) and its a POJOs based then JGroups will be the best fit for detecting node addition and deletion scenarios (may be one of the best available options).