Runtime Spring Bean Swap
Ok, the post topic is a bit grandiose, it should have been “Development time swap of spring beans using a custom classloader”, so a few disclaimers, I am only talking about development, I am not aiming for the most optimal solution and yes I am still working on it. The blog is about an approach that comes with some code snippets. Is more of an idea implemented for a very particular problem which can be applied in a more generic way rather than an actual generic solution.
Continue Reading 2 comments December 15, 2008
Using Java XML API
Author: Fazal Gupta
Introduction
Java XML APIs have been one of the most used APIs in Java world. Still I think most of you would agree with me that there are so many mysteries in it, that even for developers who have been working on them for ages, it is a bit scary. The cumbersome implementations have only multiplied the horrors. But fact of the matter is whether you love or hate them, you need to live with them and use them in the most effective manner to solve the problem at hand while spending minimum of your effort in figuring out ways to parse the XML. In this article I would like to mention few small idiosyncrasies which I had to face while working with XML APIs. I have worked with Xerces and Xalan implementations and therefore my experience is based on these implementations.
Continue Reading 2 comments September 1, 2008
Java Debug 101
Author: Apurba Nath
Anyone who has done some serious development knows about debugging. There is a lot of stuff that goes under the hood for debugging, this blog takes a look at some of these. After reading this blog the reader may have a better understanding of the reason behind rare but weird errors about the “line number information not being present” when we try setting a break point. To keep things simple I am going to cover only the basics and will oversimplify and generalize without much discretion.
There are two parties in debugging, one the program which is running and the other which is issuing debugging commands to it.
Continue Reading Add comment August 25, 2008
Querying it jQuery way: getElementsByClass
Author: Abhishek Khurana
I have got a JSP page which after being rendered needs to call an onload event to look for all divs (believe me there are many of them) having some style class assigned to them and hide them from view. This is one of those kitchen sink problem that came back to haunt me making me realize that JS DOM API doesn’t give me anything to fetch elements containing a class as one of its style attributes.
I came across one of the implementation which goes like this: (more…)
8 comments July 7, 2008
Concurrency and HashMap
Author: Pavitar Singh
In theory everyone knows Hash Map is not Thread Safe and it shouldn’t be used in multi Threaded applications. But still people come out with their own theories that they can use HashMap in their context. Some say they are just reading the data and map is not written to a lot. Unfortunately none of these explanations holds good when one lands up in a synchronization issue. Normally most of the guys do not understand fundamentals around Java Memory Model and Concurrency .One cannot blame them for not knowing their fundamentals as its hard for people to visualize concurrent executions since from college days we are used to sequential executions of program. (more…)
4 comments June 29, 2008
J2EE Applications and Clusters
Author: Fazal Gupta
Issues in porting existing Applications on Clustered Environments
The ideas mentioned below are based on the practical experience of porting an existing application over a clustered environment. The work around and the solutions mentioned below should not be taken as “best practice guidelines” but possible quick fixes which may be needed to make sure that the application can run in a stable fashion without causing serious issues though with some trade off on scalability.
Environmental Setup of Cluster
The typical cluster being discussed here is not application severs cluster where the App servers are started in a clustered mode. Here multiple instances of App servers were started on different machines connecting to the same DB and a load balancer was placed in front of them for receiving requests and forwarding it to one of the App Server instances. (more…)
4 comments June 19, 2008
Java Volatile is Powerful
Author : Pavitar Singh
Java supports two intrinsic concurrency mechanisms “synchronized” and “volatile”. We tend to use synchronized or its newer avatar “locks” from java.util.concurrent most of the times without even checking if volatile or some other option could have been a fit. A careful analysis from concurrency perspective could yield a much smarter and performant solution in many of these scenarios. This analysis would need a good understanding of the properties of each of this mechanism, some of the guarantees that they hold and how it impacts a typical program.
This article takes a look from a Java perspective at some of these semantics and guarantees and does a comparison between synchronized and volatile on some of these parameters. I am also going to go over usages of volatile to build highly performant concurrent programs. (more…)
6 comments May 25, 2008
String Concatenation and Optimizations
Author: Apurba and Pavitar
A smarter brain than mine at work, pointed out this interesting article to me.
Java String Performance testing
It talks about string performance testing. I could make sense of most of the observations made in this test and thought of sharing it.
In short the test compares string operations like “+”, “new String” and then “+”, “+” with fields and then StringBuffer append. One of the conclusions of the test is
the ‘+’ operator is not evil when used with Strings
I agree with this statement and a look at the generate byte code pretty much convinces us of so. But, a word of caution here, it always makes sense to check this on our target compiler before committing to it. (more…)
Add comment May 5, 2008
Hibernate query cache
Author: Apurba
In this blog, I take a look at the query cache, well it is more than a cursory glance, would try to dive in some detail. The blog would explain some of the details of it (enough introduction, lets get to the meat).
As most of us already know, hibernate supports plugging in external cache providers for addressing certain aspects of performance. There are some very good articles on hibernate caching, some of which are
Understanding the second level and query cache
Chapter 19: Improving performance
Lets start with what we are trying to achieve by query cache. The intention is to cache the results against the query (the sql along with the parameters and their values). The effectiveness of the cache is determined to a large extent by its invalidation logic. The isolation level semantics that we want the cache to follow also impacts this logic. In this blog I will go over some of the these details and how it impacts some of the performance choices I need to make. Rather than detail the implementation logic, will run over some common scenarios explaining the implementation detail along the way. (more…)
3 comments May 5, 2008
Internationalization – Registering Custom Fonts for Apache FOP
Author: Fazal Gupta
This is a small article which explains the steps to register custom fonts with Apache FOP engine. Registering custom fonts with Apache FOP becomes important in the context of Internationalization, especially if one wants to display CJK languages in the PDF being generated. The context of this article is when fop is being used in other application for generating PDF for some XML data.
Step 1:
Install the required fonts to your OS. E.g. for Windows the fonts should be installed using the Control Panel or by copying the fonts to Windows Directory\Fonts.
If one is looking for Chinese/Korean Language, MS GOTHIC is a good font carrying a wide range of symbols.
The font can be in a standalone ttf (TrueType Font) file or a ttc (TrueType Collection) (more…)
Add comment April 28, 2008