Sunday, May 27, 2012

A snake Friend in the Society... Montane Trinket Snake...Non Poisonous



    It was 26-May-2012. Saw this beautiful snake in the passage of my Wing at the ground floor at around 9PM. I think it was ~2.5 Feet in length and was so shiny and attractive!!

Luckily, my friend Ankur Mehta heard someone saying "Kill it...here it is...." etc with a thick stick in his hand. Ankur shouted from where he was, asking not to kill and wait.

Montane Trinket Snake (Non Poisonous)


   Both of us went there and saw it. It was "Montane Trinket Snake". It was a relatively common snake and NON VENOMOUS. Luckily we were able to identify it and convinced that guy not to kill it, as it was NOT harmful at all. It must be after a rat/mice/frog probably.

   Actually, more than 80% times we encounter non-venomous snakes, but its just fear (which I completely agree with) which makes us feel that it is a threat. But believe me, more than you, the snake itself will try not to have any encounter with Human. Their first reaction is gonna be, to run away. And we should give due respect to it and let it go if we encounter it in a open area like garden/bushes or something, as they must be living there for quite a while and if there has been no incidents so far, means they are not a threat for sure.

  Infact even if a Poisonous snakes bites, more likely its gonna be a Dry bite, ie. simply a bite with NO poison injected. It would use poison as a last resort where it is provoked.

Montane Trinket Snake (Non Venomous)

   Few more people came by that time, and it was looking like a circus show and most people preferring to kill it because of fear. But I was trying NOT to handle it in-front of all, as in future that simply might arouse few over-confident guys to start handling it and which might cause injuries to such sweet creatures.
  So later in the night, went with Ankur and we took it to the backside of the society where there is a open space with bushses etc. so that it can find a suitable place to hide as well as something to eat as there are good number of frogs as well there.

Please click here if you want to see all photos.

  This was my first handling of a snake in wild. Although it was nonvenomous, frankly speaking my heart was beating at double pace. Because, when I lifted it with hook with his tail in my left hand, it started twisting its body, and I had to keep rotating it in same direction in my hand, else I was afraid that its twist would have damaged its own muscles because of twists.

     But luckily, all went right and thanks for Ankur's help. Also thanks to all guys in society who co-operated and didn't panic or over reacted!!

Saturday, April 28, 2012

Spring Singleton...Use it in right way or get messed

      Content of this post expects that you are already familiar with Core Spring Concepts like IOC etc. Other very important aspect of the Spring is its Scopes of the Bean which we define in the configuration either via Annotation or via xml.

  • What Is Spring:
    But to give little brief, Spring is a framework which we can use to create an architecture where Classes and its dependencies can be fulfilled using the Declaration rather than Handcoding. So basically, most objects that you use/need for ur program during runtime, will come from the Factory which we known as Spring Framework. I know, I am using some layman terminology here, but I think this way it will be lottle clear to beginners.

     So, you will create most important objects of you application like some Service Objects, some DB connection/pool objects etc. via Spring. And it has its own advantage which you can get know from many online tutorials.

  • What is Bean:   Classes which are configured to get created via Spring. Every instance of such classes are called "bean"

       Want to focus on "Singleton" scoped bean here. It makes sure that only one instance of that bean will be present in the "Spring Container" where it is defined. Please dont get fooled by thinking that it is same Singleton object in our regular day to day life code.
    
        Singleton scope does have an advantage that it can give:
           => High throughput: because the same object is getting referred and used every time its required, so there is no need to create a new instance again and again.
            => Low Memory Foot print: because there is no need to new instance again once a instance got created.

         But with aforesaid advantages, developer must also take due care else will fall in a big trouble in no time. As you know, only single instance is available in that container during runtime, so everytime when it is referred or asked for, that very instance will be returned by Spring factory (Context).
      Here come the possible gotcha, where same bean might be getting referred by multiple threads performing may same/different method calls on that object.So, by-chance, if there are any state, that you maintain in that singleton object, may be visible to other method calls as well. And this might be un-desirable.
       By saying state we mean, some value in the instance variables of the bean. One issue I sufferred very recently can be referred by clicking here.

      
       

Sunday, January 22, 2012

Importance of equals and hashCode method in java

Hi,

   We all know that there are two methods in the "Object" class of java:

    a.  public boolean equals(Object obj) : Determines if the current (this) object and passed object (obj) is same/equal  to each other, more precisely from the business front of view, whether "this" and obj represent same data or NOT even if they both may be two different physical object in the memory.

    b. public int hashCode() : Determines the hash value of the current object to be used for direct access mechanisms like in Set, Map etc.

     There are many good explanations on internet which describes how Map and Set operations are performed, but I still see many (even experienced people) miss to understand it. They know when to use Set, Map etc. They also know that data access with this classes are fast, but overlook the reason behind it. Like how data is retrieved fast etc.There are some thumb rules to be followed while overriding both equals and hashCode methods. Please read them here.

        To me, one of the reason why this is happening is that, most people (including me as well) generally end up putting instances of String, Integer, Float, Double etc. in Set or as Key in Map. And all the magic to make sure that access will be fast is already provided by that respective class. How??, No prize to guess those two methods ;) (equals and hashCode).

    But you will start facing issues once started using your custom class to be added in Set or used as Key in the Map. Please continue reading to understand it in details.

 
1. Adding Data in Map:

Lets say we have following code:

HashMap<CustomKey, User> hm = new HasMap<CustomKey, User>();
hm.put(ck1, user1);


What actions are performed by HashMap's Put method internally? Assuming ck1 is NOT NULL

1. It calls hashCode method of ck1 and determines the bucket where it can drop the data (user)

2. If Bucket is empty, its good and simply put the KEY + Data in the bucket.

3. But, it might happen that, there is already some Key in the map (effectively pointing to same bucket) with the same hashCode, in that case:

     a. Apply equals method of current object (ck1) with all Key objects in that bucket until a match is found (ie. equals method returns true) OR all KEY objects in that bucket checked and confirmed to be NOT equal to ck1. This is the reason why people say insertion is slow in Map, Set, as it has to do some computation before really dumping the data.

     b. If a match is found for the KEY (ck1), means he has to replace existing "User" object with User object passed with this method call as parameter. It is  as good as passing the same String valued object as KEY again to the HashMap object with a new value in second parameter of the put function.

     c. If match is NOT found, then its a new KEY with same hashCode, and will again put the KEY+Data in the bucket.

2. Getting Data back:
      Lets assume, we have following code:

HashMap<CustomKey, User> hm = ....;
User user1 = hm.get(ck1);


  What actions are performed when get is called on Map (or contains on Set):
     a. Call "hashCode" on ck1 to find bucket where it can be residing. Because hasCode on (physically) same and also two object which returns "true" when compared will always return same value no matter how many times we call it, it will refer to same bucket where Key would have been stored while putting using put method.
     b. If Bucket is empty, its sure that KEY ck1 doesn't exists in the Map (Set) and it will return null.
     c. If Bucket is NOT  empty,
           i. Compare ck1 with all KEY objects, until a equal KEY object is found OR all Key object are compared (even if only one Key is there in the Bucket) in bucket to find exact KEY object whose Data has to be returned.  Don't forget, we have to do this because to different (un-equal) objects can still have SAME hashCode :) But still, this is the reason why people say retrieval is FAST in Map, Set, as it has to seach in only a subset of the whole data in the Map/Set in ideal conditions to reach to the data. Imagine otherwise you will have compare ck1 with many more KEY objects others wise.
     d. If No KEY is found which is equal to ck1, return null.

 3.  So, Where is the issue???
      Some of you might have already got answer for above question by now, but for those who still scratching their head or pulling their hair, don't worry ;) , I will try my level best to explain it.

     Answer/Problem lies in the Default behavior of equals and hashCode methods. When we declared our own Key class, KeyClass, it is extending Object class inherently. So the implementation of equals and hashCode is already there with this KeyClass as well. But its a very rigid implementation as Object class doesn't know "what business logic you have to decide whether two instances of same class are logically same to you from the business perspective. Also what are the attributes in your class that you can use to make sure that hashCode method returns proper hashCode" following all the guidelines to be followed for hashCode  method.
   For these reasons, the default implementation of equals and hashCode methods are as followed in the Object class:
    a. equals: If both object refs are to physically same location in the memory its assumed to be equal.
    b. hashcode: Basically the default implementation of hashCode() provided by Object is derived by mapping the memory address to an integer value. If look into the source of Object class , you will find the following code for the hashCode.

public native int hashCode();

It indicates that hashCode is the native implementation which provides the memory address to a certain extent.

  So if you make hashCode method to return hard-coded value (say 1) for all object of the class KeyClass, then all the KEY+Data will be kept in the same bucket in the Map's put operation. Effectively forcing java to to do sequential search on all the Key objects in the Map while retrieving the data back. If you by mistake apply logic to return some random hashCode even for the same object with multiple call to hashCode method, you might endup with inability to retrieve the data back from the Map as it might point to different bucket while getting data back.

 Similarly, if you don't implement equals correctly, you might endupto situation where you can't retireve the data back from the Map/Set.

  So, if you add Key + Value object in the Map/Set and then to retrieve the data back from Map, you will need physically same instance of KEY, else code will NOT return data even if the KEY object pass while retrieving is logically same from the business perspective!!!!

  One of the practical example of this issue I have faced myself is while using Grails with Hibernate Caching ON. Using Query Caching, with dynamic finders, makes use of equals object. Inherently its mechanism by which Secondary cache works. Details are provided here.  (http://jira.grails.org/browse/GRAILS-5893)
  It was a big shame to me that it took me almost a year to figure out issue even though I knew these concept of hashing, equals methods, hibernate secondary cache behavior etc. even before facing issue. Its all about facing the issue practically and knowing theory and then relating them to each other to reach to the solution.

Monday, August 22, 2011

Is Jan Lokpal really worth for what its been talked about?

Came across an article on The Hindutimes: http://www.thehindu.com/todays-paper/tp-opinion/article2380789.ece#.TlJ3aKOaibt.facebook

Nice points, can be taken into considerations. but few things still remains as is:
1. Good points about the donations that they are getting from. I think they should make it available on their websites with audits details and Incometax details.

2. Yes, even I get fadeup of news channel when they dont have anything else to show n their so called "News Channel" That too showing things 1000s of times again and again. But not showing/doing real intellectual debate/discussion on the same. Even if they do so, that are time bounded, hardly 30 mins. It should be given enough of time to discuss upon. Its not that Janlokpal bill drafted by Anna and team is THe best, might be some decisions by Govt. bill are good for some reasons. But then they should be discussed and clarified at the public level. Govt. should come-out and give a detailed explanation of why they feel threat on some demands of the Janlokpal bill which might spoil the public interest, and so that can not be accommodated.

3. She is claiming that some things  in that Demands are unlike Gandhians. We should not forget that gandhi also never asked to get half independance. He also asked for "Sampurna Swaraaj,...Complete Independance!!" from Britishers. To  Britisher, at that time, this demand was also a huge demand. Something they never wanted to grant so easily. So we should not compare that way atleast while saying that current demand is not Gadhian.

4. Agreed that this movement has got way more traction compared to other movements. But again, can't we feel that this has been kind better organized in a way? And that this touches the very root cause of the problem that every individual is facing? "CORRUTPTION" ? May be this is oone more reason why it got so much of attraction, as its more generic in nature. Name any issue that we face in our daily life,, most of them drilled down, and we feel that its some sort of corruption at some level which caused the issue. Call it in-efficient PDS system, improper Food storage system, bad shape of Public schools, Hospitals etc.
 
5.Yes, agree with point that they asking to create a Huge (Draconian???) thing in  parallel in a way when looked from narrow perspective. But its not always true. There are so many reasons why we need a powerful mechanism function operating. One might get those reasons if  see through (all) following videos : http://www.youtube.com/watch?v=2CHcKlIsvAQ&feature=share
   Biggest problem we have is that, we dont have big and clean Nationalized party/ies with us now whom we can elect. BJP and Congress are the only two truely speaking big and nationalized parties with us. We have tried both of them in last 60 yrs.
    Its not that we have not done any progress. We definitely have. But again look around and look how concentrated the growths are at few places only. Our villages are still far from even basic needs fulfillment. Even post 60KM radius of Mumbai, Capital Hub of Country not having proper Light, Water supply, Roads!! I have been to the places (hardly 15 KM away from Virar) and experienced it. Then only I am writing this. I am not saying the govt. is the only one responsible for this mess. But They are def. one of the reasons for the mess. Its the duty of leader to guide people. Be a role model.  

6. When said that this Janlokpal will create a huge and powerful system, yes there is always a risk!! But I want to ask all, do they think "Autocracy is Bad and democracy is Good?" I dont believe so. Everything is good, if the power is in right hand. Even Autocracy can be better than Democracy at that time. Even in democracy, we eventually endup giving power to few people whom we elect. What if they go mad after getting power in their hand ? Risk remains the same!! How can Shibu shoren reach to a level where he is when there are so many allegations on him?

    Our democracy giving us right to elect  ... but are we getting right candidates to elect from??
 
7. We have already tried giving power to them, it has not worked all well, and we know that. Why not we try this if one still feel that this can be a monster.We anyways are not  in shade of angel right now!!

8. What does she meant by "Contrary to Gandhiji's ideas about the decentralisation of power". If that was so, why we had PM that time. Why we were trying to reunite the small statets like Hydrabad, Kashmir etc? If there is a single country, there also has to be a atelast some single source of power at some level to bring in all power across. Even in Jan lokpal, there is something called as "Lokayukta" and "Lokpal", Lokayukta is at center level and Lokpal at the state level.
 

Came across one more article today. Worth reading it. It gives many answers as well asked by dear Arundhati. : http://clearvisor.wordpress.com/2011/08/23/why-i--rather-be-anna-than-arundhati/

     So not sure why we calling it as a single huge draconian? Isn't it relatively safer when its says that all evidences will be available to public once the charge of misconduct is proved ? Or we love our system where Bhopal gas tragedy case never ends, Bofors scam get a clean chit, those who are accused can at max spend few years (if atall sent to jail) and then enjoy rest of the life as the loss to public money is never recovered from them!!

Saturday, August 20, 2011

Why Janlokpal, and should it be JUST Janlok Pal only??


Here is an interview of Mr. Nandan Nilekani and his view for the Jan Lokapal bill and the reactions of Public over it.




First of all sorry for long Kathaa below. You can skip from reading it :p

    I agree with his point that Lokpal alone will NOT shunt corruption, but at one point he says that he doesn't understand why this has got so much of traction. Thats what surprised me!!

1.   See, not every can think/foresee in broadway. Like himself, he was repeating UId for most of the discussion part, saying it can  be a area where with improvisation, things can streamedlined, agreed. He is expert of his domain, so he knows how to get best out of it. Anna is carrying different background, he is expert in his domain, and trying to get best results via that. He might be thinking in much broader way than he talked here, but he either didn't or couldn't speak because of whatever reasons, but we all have to agree that its not a overnight change. As he himself said its like a revolution of expectations. So we can't change everything in one go. So may be we can take this thing as a first step of a long journey.

   Its like collective effort from all sides which can make a better world (NOT JUST INDIA)!! WHo knows which other country can take some inspiration from this :)

2. There are so many reasons why people are NOT in state to rely on the Standing committee and other advisory boards ONLY. He claims that all doing great jobs. They might be, but how many times put of  100 things they do? If things are really so, how can so many scams (mines, 2G, CWG) can happen so easily? How can these things happen so consistently?
    May be because of Lack Accountability and unlimited freewill/power, maybe upto certain extent.

     Public pressure is there, just to make sure that, they realize the fact that "This time People ARE WATCHING THEM" and this is NOT gonna be just another sugar coated pill they can give us and fall a sleep again.

3. If you see a cop on road talking with a driver, what is the first thing that comes in our mind?? The answer to this Q would tell why we want some Monitor over all of us. Its not that Govt. only is corrupt. Even Govt. is madeup of common man only. Majority of Babus, Poilce and all other sort of Govt. employees are common man only. So my perspective to monitor is that, "its monitor on all who lives in here, not the Govt in reality". Again, its not just the Cop's fault here, to be very clear so dont get offended with me :)

   I am neither against Nandan Nilekani nor against Anna. Infact I WONT call myself follower of Anna. I have my own way of combating. If you don't believe, just read my old blog: http://yagneshchawda.blogspot.com/2011/06/how-we-can-posibly-get-rid-of.html

   Every1 knows if Anna says "no one who has done a corruption in his life so far should support and come and join his movement", not even 5% mass should be there. Yes I am saying Five, and I think even that is too big number!! But can't we give all a second chance? Many of them must have been in a situation  where even if they are right, they have to do wrong stuffs just because of NO other alternative or-else they will be in even bigger trouble. Just try reading below article, you might get why am saying this:
http://www.facebook.com/notes/abhishek-rai/the-arvind-kejriwals-blog-a-must-read-incident/10150276202014033

 Currently If individual is right, but Not influential, s/he doesn't worth anything. But no matter if he is right/wrong, but if Influential "All is Well, rest all, go to Hell !!" Have we learn anything from Jessica-lal case?

    There is so much to talk and debate on this, but sadly we hardly get time to introspect it and discuss this with self only, forget abt doing it with others.

  So friends, as I always believe,
  1. Self monitoring is the key
  2. But, Monitor over is to make sure that self monitor keeps working.
  3. And they are are again cyclic in nature 1 <-> 2 ;)


  I am sure, you must have fallen asleep by now!! 
If yes, I acheived my goal, and if not, post/share this articles and let others feel the Joy of Sleep !!!  ;)
 

Sunday, July 24, 2011

Here are couple of new snaps my library....more avaialable @ http://www.facebook.com/media/set/?set=a.2240041719967.2130444.1215754687&l=44094ba8cf&type=1

                                         
                                          1.
                                          2.
                                           3. Baby kingfisher @ my society

Saturday, June 18, 2011

How we can possibly get rid of Courrption?


At one of the discussion thread where poeple were thinking if "Can Threat to Fast untoo death will get end to corruption or not". Here is my perspective to it. Although I have respect for Mr. Anna Hazare, so dont mis-interprete this blog.
      There is only One simple alternative, that is Change Ourselves.

          Perfect world never exists. We have to tame the level of evilness, thats it.

     Every corruption (big/small), is somehow touching aam-adami at some level for his involvement. eg. Govt. employees (most of them are aam-aadami only) had their small portion of interest in all corruption. If majority of them make sure that they dont get currupted, just image how difficult it will be for even big ministers to do corruption. They can start doing their job with sincerity.
 
      I m not just pointing at Govt. employees. We who are either in business, employees can file right Income taxes, thats the way we can make sure that we doing our job (of filing IT) correctly and ethically. Dont forget tat we can't blame others unless we are not clean.
 
      Its easy to get Power but difficult to digest it. We have Power to do some tax ka zhol, we and we do it, just imagine, Neta are having bigger powers with them, so they use it at that level. Its just the scale difference, nothing else.

   Also never forget "We get Govt, that we DESERVE. So first we have to make ourselve Deserving." Like rightly said, "Deserve b4 u Desire"

  Dont forget, we have very small memory, GoI is having a very small, simple but effective algorith for this problem:
1. We forget everything and we get bored of everything in just few days. We forget many important thing if India Wins World cup or Shilpa Shetty is getting married!!
2. GoI knows this very well and thats what they are exploiting.
3. Aam adami will join Mr. Anna for 2-3 or may be 5 times for his fastening. Every time Govt. will ask for some time or create some so called committe of bullshitters, who will again waste time.
4. Soon Mr.Anna will get frustu of them and again will go for fast. People will support him. Few from distance, few personally. but those are personally there with him, are also aam-adami, they also have to run their family. They can't keep skipping their business/ office and join Mr. Anna.
5. So atlast after some time Mr. Anna's streangth of mass with him with get shreded.

   I feel, Mr. Anna, and others whoc are also dreaming a future of less corrupted nation, should only spread word of mouth, and make poeple more awake about how being non-corrupted will make them and their future more happy then being corrupted and making fast money.

   Idea here is that, Janlok pal bill is NOT the solution at the end of the day. Solution is the attitude of  poeple, the mass attitude. Otherwise Janlokpal bill will also be just another "On-Paper law" in India like other thousands of Laws which are like "Toothless Tigers". An I wont regret for that as well, because we sadly would still deserve that!!!

Monday, April 4, 2011

Letter To resp. President Of India for Cricket WC-2011 logic of paying Cricketers

Hi Just sent a letter To resp. President Of India for Cricket WC-2011 logic of paying Cricketers. Here it goes.

Respected Madam,
     I am just another person living in India, and paying tax in the hope that it will be used for right cause & for right people. But recent Good incident also really make me feel sorry and low.
Yes, I am talking about Wining Cricket WorldCup. I am also fan of cricket and appreciate team for wining it. But got really sad when heard that public money is gonna be used for honoring them, that too with such a huge amount ( Rs. 1 Cr. per head )

    I am not against giving them honor/recognition. But that can be done in far better way and constructive way than its being decided. eg. with > 6 Cr. a new public school can be build or up gradation of Public hospitals can be done, which can bring joy to many lives. We can give the name of the cricketers for their honors if needed. We can give medal if needed. But giving away such a huge amount from public money that too to the cricketers where majority of them are not really in that under paid or something. Also lemme also tell you that I am also a big fan of cricket, so its not that I am writing this because I dont love this game and all.

    BCCI is NOT part of Govt. body, so do the players who are playing in it. Its like paying bonus to Employees of Pvt. Co. from Govt. treasury when that company is making profit..even that is also something that India will proud on when business will grow for that Indian Org. So should GoI declare bonus for them as well ?


    I seriously oppose these decisions. Aren't soldiers on border, Honest Police person on road etc. are way too bigger heroes than Cricket team ? Why we are not honoring them with such a great rewards? And why only to Cricket ? There are so many other sports heroes, who won Gold for us, dont we have proud on them ?
 

   I tried to send mail only to Resp. PM of India. I didn't find his email address. And sadly link http://pmindia.nic.in/write.htm to write him at his website  http://pmindia.nic.in/pmo.htm is also NOT  working.
So bothering you. Hope you will get some time out of your hectic schedule for Just another civilian. I expect a thoughtful time of yours in this issue, and hope you will take some decision which is in favor of country !!

Tuesday, March 29, 2011

Grails App Monitoring Plugin

   Just found a very good Grails Plugin for Grails App monitoring: http://grails.org/plugin/grails-melody
Worth giving a try !!

Understanding Grails GORM Secondary cache.

Hi,
  I always wanted to find out some detailed doc. which could explain me how GORM is managing Secondary cache (via Hibernate Obviously) for us. Obviously GORM gives us sugar coated way of defining Domains which are alowing us to call dynamic finders like find, findAll, finAllByXXX etc. and also allows us to fire Criteria, HQL etc. on that domain.
  You can get basics of this stuffs in grails doc. which is kind of good enough. But one thing I still feel is lacking the focus in Grails Doc. is the Secondary cache. Its not describing behavior of caching. Although part of it actually related to Hibernate, so thats why its not been docmented well there.

  Reason why I am writing this post is : http://grails.1312388.n4.nabble.com/Effect-of-Enabled-Hibernate-Level-2-cache-on-Domain-td3405253.html

Here are some basics that we should know atleast before going to further details.
  • There are dedicated regions for Domain cache and Query (standard query cache) cache. And one more special region called as "org.hibernate.cache.UpdateTimestampsCache". You will find enough docs online to understand what "org.hibernate.cache.UpdateTimestampsCache" is. So I wont go into its details for now.
  •  Dont forget that Hibernate Queries will get cached only if Secondary Query cache is enabled.
  •  Domain cache puts (a single row) Domain Instance in this cache region with key generated as follows: [Fully.Qualified.class.name:PrimaryKey]
  • Domain cache regions can be futher be customized to store a particular type of Domains only. This is to handle a situation where some domain cache has to expire soon or infrequently, or number of domain to be cached as to be different than other default cache (maxElementsInMemory) size.
  • Standard Query cache region is a seperate dedicated region, created automatically by Hibernate to store the results of the Cached Queries. It stores PK of all the rows that comes as result for the Query being fired. Its key is generated with following things: QueryStatement and Paramters map. This is because same query can be fired to get different result, for example to get paginated view, we keep on fireing same query, what we change is just the offset/start_index paramter in the query. And when results are got, we have to keep it seperate for each page in the cache.
  • If query cache is enabled in hibernate config, (datasources.groovy in our case), still to make sure that Dynamic finders caches it, we have to add cache:true in the params that we pass to the method. But list() method will not require it. It seems to assume put in the cache if query cacahe is enabled in hibernate config (datasource.groovy)
  • Mapping cache true declaration in domain allows domain instance to be part of Secondary cache regions which is dedicated for storing actual domain objects

Scenarios:
  1. Hibernate Cache + Query Cache is enabled, *NO* mapping of cache true in domain class, but cache : true specifieed in dynamic finder (findAll and findAllByxxx and criteria etc):
    •  If we fire dynamic finder like (findAll, findAllByxxx) with Query cache = true.
                i. Query resuls (PK) gets stored in cache. But Domain itself is not Cacheable because we have not mentioned mapping cache true in Domain class, Hibernate wont put it in the domain cache.  So if you hit same flow with same paramter again, Hibernate knows what all rows it requires as it knows PK of all rows in the results set for given query with specified paramters,
               So it fires individuals queries to DB for each expected rows with its PK. So assume that for the first time when Hiberate got 10 results for the given query and its params, if you fire same query with same params, hibernate will fire 10 (YES its 10) select SQL queries which is really * BAD *
    •  If we fire get(PK) method, and assume the PK we are already looking for NOT there in the Cache, it will get it from DB and CAN NOT put it in cache. So that every time you fire get(PK) it will get data from DB.
    •  If you did a insert/update anywhere in the table, whole Query Cache for that domain (of that type) will become invalid. Doesn't matter if Update has any changes in the Domain instance you are interested in or not. Its logically in-correct, but practically its too difficult to implement, and Hibernate guys have taken the obvious and simple route there to handle this situation by invalidating the cache. Domain cache for this cache is anyways ot having Domain o fthat type as cahe true mapping is not declared.
  2. Hibernate Cache + Query Cache is enabled, Mapping of cache true in domain class, but cache : true specified in dynamic finder (findAll and findAllByxxx and criteria etc):
    •  If we fire dynamic finder like (findAll, findAllByxxx) with Query cache = true. Query resuls (PK) gets stored in cache. So if you hit same flow with same paramter again, Hibernate knows what all rows it requires as it knows PK of all rows in the results set, it checks in secondary domain cache for PK, and it finds it there so no need to go to DB. * GOOD *
    • .If we fire get(PK) method, and assume the PK we are already looking for is already there in the Cache, it will get it from Cache, else will go to DB and put it in cache as well apart from returning to you. So that next time you fir get(PK) and cache is still valid, it will get data from cache.
    •  If Domain instance you want is already in Secondary cache, but you did a insert/update anywhere in the table, whole Cache (Domain Cache + Query Cache) for domain of that type will become invalid. Doesn't matter if Update has any changes in the Domain instance you are interested in or not. Its logically in-correct, but I think practically its too difficult to implement, and Hibernate guys have taken the obvious and simple route there to handle this situation by invalidating the cache.
    •  Dynamic finder's results are in Query cache. Suppose it returns 150 Rows. So Domain cache will have to store 150 domains in it. When you dont have enough space in memory to hold all those data, it should ideally overflow to disk store if enabled. This time your domain class will be stored in a disk file managed by eh-cache internally. You mention where to keep that files on disk in ehcache.xml file with <diskStore path="user.home/ehcache_data"/> node.

  I will keep adding more details as I will learn more of this.
All kind corrections or inputs are welcome !! Feel free to comment here or reply me on my email address as mentioned on facebook.

Friday, March 18, 2011

BSNL Broad band Pune Issue (resolved)

Hi,
  I got BSNL dataone broadband at Wakad, Pune just 2 days back. Since day one I started facing issue. Not that net is not working and all. But it used to stop loading page inbetween for many websites. And funniest part was that even facebook pages at times never used get loaded completely. I saw many js, image files are never getting loaded completely.

   Initially I thought some issue with DNS. But As half of the page is getting loaded from the same domain where download is stuck while loading is going on, its really not possible to blame DNS.

  This made me really crazy, my half a day was wasted because of this while I was developing an app using Facebook Javascript SDK. It never used to download http://connect.facebook.net/en_US/all.js, but facebook domain is always reachable with traceroute and normal page load during browsing.

  Issue got resolved final in my router configuration. I set TCP MTU=1300 and magic happened. Frankly speaking I still need to go through greater details about significance of this field, but for now this tweak is atleast allowing me to keep a smile on my face :)