Tuesday, December 1, 2009

Database Connection Pooling

Database Connection pooling should be the first taken for performance optimization. C3PO offers connection pooling most used in Java projects. There are some properties which are basic like minPoolSize and maxPoolSize. minPoolSize Should be atleast equal to number of concurrent requests you foresee on your website. maxPoolSize, maxIdleTimeExcessConnections, acquireIncrement can be used to for handelling exceptional overload on server.

maxIdleTimeExcessConnections can be set to 5 minutes. It will bring back active connections to minPoolSize from maxPoolSize if it is idle.

maxStatements and maxStatementsPerConnection are used to save compilation time every time u call prepareCall. But it dont help. Keep both 0. If you set maxStatements as lets say 50 and if the size is consumed by current request there may be bottlenecks and Spikes. So avoid it.For maxStatements, It doesnt make sense compiling statements in application server because there may be 1000s of SQLs in your application.

Call Centers Tricks

Having a call center is important for every corporate. But are the call centers, customer cares or support desk becoming successful in actually solving the problems of customers. Recent interaction with an reputed Telecoms operator brought in front of me different ways/tricks which these call centers use to hide incompetence's. These call centers are acting as levels of shields which dont allow customers to get transparency and problem solved. They have range of tricks which are..

Trick 1: If your existing ticket is not solved till dead line, they might raise new ticket and buy time.
Trick 2: When you call the call centre they might put you on hold endlessly asking you that they are transferring to different department.

Trick 3: If you wish to speak to senior or manager they might transfer to some of their colleagues, i guess, who acts as senior.
Trick 4: They give phone number of nodal officer which is always switched off or engaged.
Trick 5: They give you time by when the problem will get solved and then without solving the problem, i guess, make a confirmation call saying problem is resolved.
Trick 6: If they are supposed to call you, they will give 2-3, i guess, missed calls and before you pick up disconnect the call. Later they say we tried to call you.
Trick 7: Will divert your phone to other state call center. Eg: Punjab or any other state.
Trick 8: They will hardly revel a facility like nodal officer email id. Even if you contact Nodal officer he will take sweet 5 days to reply.
Trick 9: If at all phone gets transferred to so called manager, he will give promise to solve the problem- but in 15 days.
Trick 10: They never give the phone number of the technical person who is actually going to solve the problem.
Trick 11: When a ticket is raised a completion deadline is given as 3 working days. However they dint seam to do any thing till the last minute and when the deadline is passed they ask for 2-3 additional days.
Trick 12: They close the ticket very often saying that there is INCOMPLETE INFORMATION. They wont even inform you about the closure.
Trick 13: The phone can be diverted in various department like GPRS, network, technical or customer care.
Trick 14: They will make a call asking you when are you at home for a technical person to visit at home personally. Obviously, most of us will not be at home on working days and the technical person will never have to visit your house.
Trick 15: They anyways have to auto option to auto cancel a phone number when he calls call center for 5-6 hours.
Trick 16: It is also common to suggest useless solutions and close the ticket. Like handset problem, simcard problem, restart mobile.
Trick 17: Ask the customer to get in contact through email support with reason given that email support is given more priority. In practical, both have same priority.
Trick 18: If you some how get call from technical department to inform you that the problem is solved, chances are that you will not be able to call back on that number. If some how you are able to call back on that number, they will ask you your mobile number to call you back. But in reality, i guess, they take your phone number and feed it in they local number or note it physically and ensure that they don't pick this phone number.

Words i guess means that me as a customer cannot prove the action but a perception is formed and harm is done about the image of call center.
As you don't have even a single person whom you can catch hold of and with so many options in call centers arsenal, you can only hope that your problem gets solved.


The attitude of people sitting at call centers, i dont know weather its officially taught to them or they themselves have invented it, would promote unnecessary inefficiencies. The technical team would be willing to solve the problem but if the call center guys are used to think that the problem is from customer end, even the genuine problems goes unresolved. I think that the number of employees in technical departments should be good enough to back the actual problems. If not surely business will not be able to scaling to higher limits.

It has to be noted that a single problem solved actually would reduce the N other number of calls as some problems would be faced by many other customers. With recovery in sight its high time to get technical teams on work to solve each problems which customers are facing and be able to scale successfully. Would end it with a funny note that this entry also helps callcenters those who have not yet implemented trick like above and can hence forth use same at their respective areas..

Sunday, October 25, 2009

Port 80 may not be a clean path

If you want to host a socket based application on internet, port 80 may not be a clean path to be picked.

A socket based application could be used when application creates a socket and communicates using custom data format like xml and delimited texts.A chat application is a example of socket application. There is a need for continous open connection which will flow chat text to client from server.

Generally client application which wants to do socket communication can rely on technique of http tunneling where a get request is made to a web server and once the socket is opened custom data fromats could be exchanged.

The problem faced here is which port should be selected for hosting chat server.
Selecting port 80 will work in 95 percent of cases and 5 percent of users might face any of problems mentioned ahead.

Request/Reponse: An ISP may route all the requests received from port 80 through proxy server. Proxy server works on request response basis, which means once request is received and forwarded to server and server has started responding, no more request can be received from client on same request connection. So the upstream data or the outbound communication on the client system may not work or hang.

Buffer data: An ISP proxy may buffer given number of bytes received from server and then flow the data to client. This may be done for caching at proxy level. It can also be used to detect if the response is any virus file. However, as per my knowledge hardly any ISPs scan for virus data.In this case inbound link may hand till configured bytes are read.

Proxy Load Balance: Some ISPs may route each request received from client on a load balanced proxy servers. This will cause each request to get different IP. To experience this you can visit www.whatismyip.com and check if your IP address is changing on every request. Try it 5/6 times to ensure it. This may affect those services which are using source ip for some kind of processing on server.

Header modification: When the data is routed through proxy servers at ISP, there are chances that the proxy server may add some additional headers on your reponse. If your application is not tolerant then you may have hard time solving this issue.
Some spyware installed on clients system mostly monitor request on port 80 and may tamper with request response headers.

Antivirus,Firewall,Spyware: However these are client end configurations, if may also affect socket communication. The application executables which are making socket communications should be added in antivirus and firewall exceptions.
Spyware are nasty to the extent of discarding application headers and putting their own headers. So avoid sending application data in http response headers. Your http response headers may not reach client system or may be manipulated.

Choosing a non 80 path may save you from above problems. If all your clients are using direct internet connection you may easily use non 80 port. However if you have users sitting in corporate offices surfing internet thorugh corporate proxy server then selecting non 80 path may be difficult.

This blog entry also to some extent explains how ISPs work internally. If you want ensure that your application works with with most ISPs do test you application with atleast 7-8 proxy servers before going on internet.

Monday, September 28, 2009

Development of Rural India

Although india is a fast developing nation, but the benefits of development is not reaching in deeper part of india. Unemployment, lack of basic infrastructure like Roads, Irrigation, Electricity are major problems. if these problems are solved through some structural changes india can become super fast growing economy.

Road construction companies should keep doing surveys about where they can create new roads n where they can do repairs. Instead of government ordering them they should proactively do it. Same applies to Dams construction.. Development should be pull based rather than push based. Somewhere i feel that indian corporate is more trustworthy than the local political representative.

Government has to solve irrigation problem asap as farming is still not a profit making business for major section of farmers. There is huge risk in farming as much is dependent on rains. If government cannot gurantee irrigation then farming should be nationalised in such regions. Afterall government cant leave people to make irrational choices of doing farming n trapping themselves in losses and debts. Many times farmers take double risk of rains and cash crops which often proves fatal.

There are so many industrial estates which are under ot not utilised. Work should be outsourced to from urban areas to such remote locations and railway frieghts should be waived on such outsourcing.

Sunday, August 30, 2009

Swing ResultSet Column Table Component

Hear is a ready to use component for JTable in swing which will also show column titles. By default the JTable only displays the data which is strange although. This code is free and can be used easliy in commercial and opensource applications.
Yet this component does not have alignment facility depending on Integer or String or Date datatypes. Will update once done.

Steps to use the class
1. Create a class ResultSetTableModel.java in package src.components.
2. Create a JTable and add it to JScrollPane.
JTable tblSuppliers = new JTable();
tblSuppliers.setVisible(true);
JScrollPane scrollpane = new JScrollPane(tblSuppliers);
pnlCenter.add(scrollpane,BorderLayout.CENTER);
3. Create the ResultSet,Create Model and set Model.
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(strQuery);
ResultSetTableModel qtm = new ResultSetTableModel();
qtm.setResultSet(rs);
tblSuppliers.setAutoCreateColumnsFromModel(true);
tblSuppliers.setModel(qtm);


Code for ResultSetTableModel.java is as follows.
package src.components;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class ResultSetTableModel extends AbstractTableModel {
Vector cache;

int colCount;

String[] headers;

String currentURL;

public ResultSetTableModel() {
cache = new Vector();
}

public String getColumnName(int i) {
return headers[i];
}

public int getColumnCount() {
return colCount;
}

public int getRowCount() {
return cache.size();
}

public Object getValueAt(int row, int col) {
return ((String[]) cache.elementAt(row))[col];
}

public void setResultSet(ResultSet rs) {
cache = new Vector();
try {
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();

headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = meta.getColumnName(h);
}

while (rs.next()) {
String[] record = new String[colCount];
for (int i = 0; i < colCount; i++) {
record[i] = rs.getString(i + 1);
}
cache.addElement(record);
}
fireTableChanged(null);
} catch (Exception e) {
cache = new Vector();
e.printStackTrace();
}
}

}

Saturday, August 29, 2009

Browser Embed In Swing

SWT Browser component is quite handy when you want to include support for platform independent browser support from your swing application.
Its more over important when you want to show modal window with a browser, because in case of non modal window you can anyways start IE instance from Runtime call.

The benefit of using Browser component in Swing is that it gives you enough control over the contents you can change anytime from website.
Also its saves you the time of rewriting the stuff written in Website again in Swing or AWT. Same stuff can be used here by directly pointing to Website Form/Page URL.

You have 2 options to go with.
1. chrriis.dj.nativeswing.swtimpl.components.JWebBrowser and
2. org.eclipse.swt.browser.Browser

I would suggest you to go with SWT Browser component.
One problem you will face with JWebBrowser is that the component creates problem with java 1.6. Its makes whole application
go crazy and all screens seams to get repaint problems.
Another problem you will face in JWebBrowser is that the component shows Custom window then a window.open call is made in
HTML page. You might like to open it in Default webbrowser of your operating system.
It allthemore becomes unacceptable when you have shown JWebBrowser component in JDialog window and you have clicked on window.open link.
It will show a window which is kind of hung and you cannot scroll or do any thing with the new window until you close the modal window.
One more problem you will encounter with JWebBrowser is that if you want to decide if opening of new window is to be allowed should be allowed
or not on the basis of URL location clicked, you have to
make a hidden JWebBrowser Component,
set it as browser instead of new window browser.
Dispose the new window using arg0.getNewWebBrowser().getWebBrowserWindow().dispose() in windowWillOpen open.
Ensure that you dispose the new window before setting the webbrowser.
Cancel the Opening of URL in locationChanging event and get the URL.
These long steps are to be followed if you want to intercept the opening up of new Window.

Good thing about JWebBrowser is that it is licensed under LGPL. So you can use it in your commercial projects also. You need not publish your code to users in case of LGPL.
A word for Christopher Deckers, author of JWebBrowser. Please make it work under Java 1.6. Just a call to NativeInterface.open starts the problems of repainting the windows.

However going with SWT Browser is not a eazy path either. You may face problems like
1. JVM Crashes
2. Not fitting easily in JDialog window and fits in JFrame.
3. Browser opens up in JDialog only once and dont come up next time onwards.
4. Your JDialog window shows up but the Browser dont show up.

To avoid JVM Crashes ensure that your window creation and displaying is all in SwingUtilities.invokeLater.
Let the shell loop be out of SwingUtilities.invokeLater. To ensure that JDialog and Browser both shows up,
you set location, size and visible for canvas, shell and browser component.
To ensure that the browser always comes up on window you might have to make use of small sleeps of 1 second outside your SwingUtilities.invokeLater.
This is to ensure that Window is created and shownup on screen before you try to set the browser component on the window.

The code written using SWT Browser component is completely platform independent. You can run vncserver service on your linux box and connect to it using vncclient and see your
application running in Linux environment using MOZILLA browser instead of IE.


If you need any advice or help on the topic please leave a comment here.

Friday, May 15, 2009

JVM Crash in Java Awt Client Exe

The JVM for Java is written in c++ language. When a JVM crashes it creats a file in hard disk from where the class is running. The file contains name of error. For Example EXCEPTION_ACCESS_VIOLATION. So how do you solve this error. The error file may state the thread in which the error occured. Once that is known you can apply some logic regarding what may the reason for crash.

If you are facing error in awt.dll and AWT-Windows" daemon, chances are that you are getting this error because of request focus. Check again the request focus calls. Some of the request focus may not be useful.

Saturday, April 25, 2009

Keep Updated to Google News through RSS

Are you in one of following situations.

1. You are staunch user of RSS Reader and less of Mail
2. You scroll through daily news paper and look only for specific subjects of new.
3. You are student and like to read more online and less from books.
4. You want to get news for all major news paper in your Reader for your topics.
5. Basically, You want Google News Alerts in Reader instead of Your Mail box.

Just now I noticed, RSS feed provided in Google News page. I dont know since when it is available, but i am quite sure its added there of late. I had a long list of subscription of Google News Alert around 2 years back. But ever since i shifted to Google Reader i have disabled all Google News Alerts.

RSS feed on Google News is rightly put there.. exactly as per my expectation and requirement..

Monday, April 20, 2009

Oracle Improves Productline

Oracle is now able to provide range of products and services to its clients like Storage, computers, operating system, database, middle ware and applications. This is because Oracle and Sun's product line compliment each other. However,clouds of uncertainty started hovering above overlapping areas like MySQL, Glassfish and Java. MySql however is not a straight competitor of Oracle database as user base is different.
This deal seems to be more beneficial form Oracle's point of view.It would be interesting to see how Java is able to grow under love and affection of this Step mother. With this deal, all Sun project seams to go on a slow track for some time as Oracle probably will be evaluating each of them and try to align them with their goals. IBM would surely be repenting on missing the deal with Sun.

Java Community favours the deal over IBM because Oracle would do more justice to take it ahead. IBM already have java based products but doesn't seam to be committed to high standards and reliability as is Oracle. Sun was more than generous at funding projects like JavaFx,Openoffice,NetBeans. This would change now I think!!

Friday, March 20, 2009

Java Serialization fails on Slow Network

Software like humans have behaviour, and more we use one we come to know about its behaviour..A Socket and ServerSocket connection was abruptly throwing EOFException in a slower network of 2 mbps but the same works without a single problem on the 100 mbps network. Apparently, Java was not throwing the timeout exception.

This problem was not coming always. The data flow of byte array was flowing properly without any problem in most of the cases.. But all of sudden, some of the packets seemed to be dropped.. As the receiving program did not get the complete bytes it was not able to construct a complete object using deserialization.

This whole problem embedded inside full fledged application makes it difficult to locate. DataOutputStream.writeUTF and DataInputStream.readUTF seams to fail.

In this process some tools came quite handy. AutoIT was a good tool for simulating user interface test cases. Its very easy to write script for making mouse clicks, keypress and window activation. I am sure its going to be useful to me in many of future projects. Another tool was Speed Limiter. When we do load testing in 100 mbps network our application works differently then over slower network. This makes it important to do load testing over slower networks like 56 kbps(Dial up), 1mbps, 2 mbps(BroadBand) networks. The timeouts, buffer size, queue size should be tuned for these network connections. We can run Speed Limiter on the Server system, on the port on which server was going to run and run the server on different port. Then we can mention the port mapping in Speed Limiter. You can select different speeds at which you want to do simulation. Only feature i missed in this tool was jerks or spike. In real network the connection gets stuck for some seconds and then starts again. This cannot be simulated here.

Coming back to core problem, i thought that there might be some software component in network like Antivirus which may be dropping/blocking some packets. But it was not the case. The problem was with the connection timeout. It the connection timeout was set to 10000 and above using Socket.setsotimeout function the problem gets solved..

So all that appeared to be a serialization problem was actually a timeout problem.

There are other serialization problems which i am facing like a long value being serialized over network gets divided by 32 on the receiving end. Then in one more case a String if has length more than 128 bytes gives StreamFormatException when serialized. I will update about same once i resolve the issues..

Wednesday, February 4, 2009

Windows Mobile Internet Connection

You will find many resources in internet which lets you use connect your windows mobile phone to your laptop using bluetooth or USB and surf internet. For those who are still living under the rocks, i would mention the steps again.
1.In mobile->Enable bluetooth on your mobile such that your device becomes visible to other divices.
2.In mobile->Using ActiveSync connect to your laptop. Put key if asked for.
3.In mobile->Start Programs->Start Internet Sharing with Connection as Bluetooth.
3.From Desktop go to start-> Connect to->Set up connection or network->Connect to bluetooth personal area network->select your mobile device-> Click on connect.

You are ready to browse internet.To confirm you can now give ipconfig command on your command prompt.Your system has got a IP now. But this is not for which i am writing this entry.

This weekend i had a peculiar requirement. I needed high speed internet connection on my mobile device. Unfortunately i did not have any Wi-Fi support on my mobile. So i needed to connect my mobile to my laptop and use laptops internet connection. I searched the net to only find that every one had this query, but no solution.
So i decided to break the nut myself.

Here are the steps i consolidated.
1. In Laptop->Download any proxy server on your system. I had downloaded Winproxy free version.
2. In Laptop->Start the proxy server. Note the port.
3. In mobile->Start Settings-> Connections->Advance-> Select Network.
Set Both the connections as My Work Network.
4. In mobile->Start Settings-> Connections->Task->Setup Proxy Server-> Check Internet and Proxy Checkboxes->
Enter the IP of your desktop where you are running the proxy server.
Click Advance and ensure that the http and socks port is the one on which your proxy server is listening on.
5. In mobile->Active Sync->Connect using Bluetooth.
6. In mobile->Start Internet Explorer and browse.

This will allow you to use the reverse or opposite internet connection on your windows mobile using bluetooth. If you are already having a internet connection and geting additional connection using above method then you can restart laptop after disconnecting the existing connection.

With this entry i am having my first taste of blooging. Hope we have a good time in future..