<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3328145809638396238</id><updated>2011-07-30T11:43:39.815-07:00</updated><category term='Devsummit'/><category term='java'/><category term='jpa'/><category term='web'/><category term='toplink'/><title type='text'>Tic Tech Toe</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dumbcuriosity.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3328145809638396238/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://dumbcuriosity.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>jitesh</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3328145809638396238.post-5002165657239695498</id><published>2010-04-21T10:02:00.000-07:00</published><updated>2010-04-21T12:59:03.970-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web'/><category scheme='http://www.blogger.com/atom/ns#' term='Devsummit'/><title type='text'>GIDS Day 2.</title><content type='html'>"&lt;span style="font-style: italic;"&gt;Small Cap, Mid Cap, Large Cap .. it doesn't matter what cap a stock is, add it to your portfolio as far as it brings a value&lt;/span&gt; to you."&lt;br /&gt;&lt;br /&gt;This is a promo line of a popular stock market analysis program on Television.&lt;br /&gt;&lt;br /&gt;My take from &lt;a href="http://www.developermarch.com/developersummit/"&gt;GIDS &lt;/a&gt;is quite similar..&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;"Presentation  tier, Application tier, Data tier.. it doesn't matter which tier a technology is, add it to your knowledge base as far as this knowledge brings your software a value"&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Few years back when one attend a web conference one would only hear 10 presenters giving 100 different definitions of Web 2.0 and Ajax . But today I saw the same presenter discussing flash in one session and power of cloud computing in another. Google and Ajax has made the end user so demanding that it has forced a  developer to move beyond his comfort zone and learn jQuery and cloud computing concepts at  the same time.&lt;br /&gt;&lt;br /&gt;Coming back to GDIS it started with &lt;a href="http://www.apl.jhu.edu/%7Ehall/#Bio"&gt;Marty Hall&lt;/a&gt;'s session on "Rich Internet Application"  where he started with what is ajax and then went on to give example using plain jQuery, JSF 2.0 and GWT.&lt;br /&gt;&lt;br /&gt;Scott Davis then decided to move beyond the curly braces and discussed Web 2.0 concepts. It was a great and enjoyable presentation but to be honest I wanted to see some grail code within those hated curly braces. But he promised there will be enough of it tomorrow.&lt;br /&gt;&lt;br /&gt;These were followed by parallel sessions and one can choose to attend those one like the most.&lt;br /&gt;&lt;br /&gt;I attended one of the less crowded presentation on "Longevity of Scalable System" by Yahoo's Nishad Kamat. He covered how to increase the shelf life of a software in the current competitive and dynamically changing technical echo  system. Presentation covered how one should overcome the familiar dilemma between home grown and  imported technology.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://denverdev.blogspot.com/"&gt;Matthew McCullough&lt;/a&gt;'s Hadoop's intro was another good thing to follow. A good intro to Map Reduce Algo and the problem it is designed to solve. Not sure if I understood all of it but I am sure very soon I am going to download Hadoop and try to develop some simple searches on my tomcat log files.&lt;br /&gt;&lt;br /&gt;I wanted to attend the "NoSQL:The Shift to a Non-relational world"  presentation but thanks to the volcano ashes, the presenter could not make to Bangalore. Ramesh Srinivasraghavan from Adobe who earlier talked about flex took his slot and gave introduction to cloud as an environment and the challenges it brings to web development.&lt;br /&gt;&lt;br /&gt;McCullogh ended the day with the important session on web debugging tool. He discussed tcpdump, netstat, curl, wireshark, MODI, Jmeter, JASH etc. I was surprised that he didn't talk about fiddler and our so simple  live httpheaders.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Looking from the kind of presentation and audience responses, one can say that developer curiosity has shifted from how to build web 2.o application to  how to scale a web 2.0 application.&lt;br /&gt;&lt;br /&gt;Organization of the even was very professional.. I just wished there was more time given for questions and networking. I would try to put a detail plus and minus post after tomorrow's presentation. But I am happy to have spent my time and money on event like this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3328145809638396238-5002165657239695498?l=dumbcuriosity.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dumbcuriosity.blogspot.com/feeds/5002165657239695498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dumbcuriosity.blogspot.com/2010/04/gids-day-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3328145809638396238/posts/default/5002165657239695498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3328145809638396238/posts/default/5002165657239695498'/><link rel='alternate' type='text/html' href='http://dumbcuriosity.blogspot.com/2010/04/gids-day-2.html' title='GIDS Day 2.'/><author><name>jitesh</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3328145809638396238.post-3905713483185008018</id><published>2007-07-21T07:13:00.000-07:00</published><updated>2010-04-21T09:38:53.090-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='jpa'/><category scheme='http://www.blogger.com/atom/ns#' term='toplink'/><title type='text'>Toplink caching</title><content type='html'>&lt;div  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;     &lt;div&gt;Despite using Java Persistence API (JPA)  for quite  some time now, it continues to remain an interesting topic to explore. I think a lot of credit for it should go to the number of "may"s used in  the &lt;a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html"&gt;specification&lt;/a&gt;. I asked &lt;a href="http://deepjava.wordpress.com/"&gt;Deeps&lt;/a&gt; why  does spec uses  "may" or "may not" when it  should have used "will" or  "will not". His reply was short but convincing.&lt;br /&gt;&lt;br /&gt;The spec is as much for the providers as it is for application developers.  There should be enough incentive left for the providers to showcase that they are better than others. The word "may" gives that incentive. I call this phenomenon as MSM ..."Magic Sphere of May". This sphere is magical  and wonderful but only issue is no body knows its perimeter. &lt;/div&gt; &lt;div&gt; &lt;/div&gt;  &lt;div&gt;As far as JPA is concerned most important thing that comes in this sphere  is caching of Entity Beans. I made a small attempt to explore it. Since I have used  toplink essentials, my observations are based on it but i am sure Hibernate and others will not be much  different. &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;Toplink has two levels of caching generally termed as L1 cache and L2  cache.&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style="font-weight: bold;"&gt;L1 cache&lt;/span&gt;: &lt;/div&gt;   &lt;div&gt;The key concept of JPA is persistence context.   JPA defines persistence context as a set of  entity instances in which for any persistent entity identity there is a unique  entity instance. Its within this persistence context that the life cycle of entities are managed. In simple words persistence context is like a cache  which holds all the managed entities , and the EntityManager interface API works  off this cache. Probably that is why in toplink terminology persistence context is referred as &lt;span style="font-weight: bold;"&gt;"Unit of Work"&lt;/span&gt;,  and the cache managing this persistence context as "&lt;span style="font-weight: bold;"&gt;Unit of Work cache"&lt;/span&gt;. &lt;/div&gt; &lt;div&gt; &lt;/div&gt;    &lt;div&gt;Each entitymanager instance is associated with a  persistence context. All entities are cached &lt;span&gt;against&lt;/span&gt; their persistent identities  (or primary key). Whenever we do operations like persist or merge, entities are registered with unit  of work. Unit of work then maintains a &lt;span&gt;change set&lt;/span&gt;  to remember all modifications  done on a registered entity. Since any changes made to registered entities will  eventually be synchronized to database, they are  also &lt;span&gt;referred&lt;/span&gt; as &lt;span style="font-weight: bold;"&gt;"managed entities"&lt;/span&gt;. You can play  around with the unit of work...update entities, bring new entities, remove  entities, but the db queries will be made only  when you commit (or flush)  the unit of Unit of Work . &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;Consider this  very simple example to see what we  are gaining out of this.&lt;/div&gt; &lt;div  style="font-family:lucida grande;"&gt;1      EntityManager em =  emf.createEntityManager();&lt;br /&gt;2      em.getTransaction().begin();&lt;br /&gt;3      Product  table = new Product();&lt;br /&gt;4      em.persist(table);&lt;span style="color: rgb(153, 153, 153);"&gt;//No insert query  here&lt;/span&gt;&lt;/div&gt; &lt;div  style="font-family:lucida grande;"&gt;5      table.setName("Wood Table");&lt;span style="color: rgb(153, 153, 153);"&gt;// In memory  change to the managed entity&lt;/span&gt;&lt;/div&gt; &lt;div  style="font-family:lucida grande;"&gt;6      em.getTransaction().commit(); &lt;span style="color: rgb(153, 153, 153);"&gt;//one insert  query here&lt;/span&gt;&lt;br /&gt;7      em.clear(); &lt;span style="color: rgb(153, 153, 153);"&gt;//clears the unit of work cache, entity "table"  is no more managed by unit of work&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;One can see how wonderfully entities are managed   behind the scenes as db queries are fired only when the state of the in memory  entity is different from the state of entity in db.&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div  style="font-family:lucida grande;"&gt;  &lt;div&gt;8     em.getTransaction().begin();&lt;br /&gt;9     table = em.find(Product.class,  table.getId());&lt;span style="color: rgb(153, 153, 153);"&gt;// one select query here, entity table again &lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(153, 153, 153);"&gt;&lt;span style="font-size:100%;"&gt;becomes  managed&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;10   table.setName("Steel Table");&lt;span style="color: rgb(153, 153, 153);"&gt;//In memory  change to the managed entity&lt;/span&gt;&lt;/div&gt; &lt;div&gt;11   table.setName("Wood Table");//&lt;span style="color: rgb(153, 153, 153);"&gt;In  memory entity changed back to the original state&lt;/span&gt;&lt;/div&gt; &lt;div&gt;12   em.getTransaction().commit();&lt;span style="color: rgb(153, 153, 153);"&gt;//no db queries  here&lt;/span&gt;&lt;/div&gt; &lt;div&gt;13   em.clear();&lt;/div&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt;  &lt;div&gt;Here since the state of entity when it was brought  into persistence context by running a finder at line 9 is same as at line 12,  there is absolutely zero database interaction on commit.There is nothing in the Unit  of Work change set to commit. If you are using JPA in Java SE mode  entities remain managed beyond transaction scope, &lt;span&gt;until&lt;/span&gt; you clear or close the  em. So Had i not cleared the persistence context at  line 7 there won't be any select query fired  either (at line 9) as entity to be found is already available in Unit of Work  cache from the previous transaction.&lt;/div&gt; &lt;div&gt;L1 cache surely saves us many expensive  queries.&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div style="font-weight: bold;"&gt;L2 cache&lt;/div&gt; &lt;div&gt; &lt;/div&gt;   &lt;div&gt;Having said that it is very unlikely that an  application will operate on just one persistence context .Normally when a  transaction is completed EntityManager is closed and new persistence  context is used in another transaction. Also an application may have several clients trying to fetch same data .In this case L1 cache is not sufficient as one client will not be able to  take advantage of another client's cache and will  always fire expensive database queries to &lt;span&gt;retrieve&lt;/span&gt; entities..&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;To solve this problem toplink has one more level of  caching whose scope is across persistence contexts. This cache is at persistence  unit level and all entitymanager created from the  same EntitymanagerFactory share this cache. Advantage here is em.find() will search in L2 cache first and hit the db only  when the desired entity is not found there.&lt;/div&gt;  &lt;div&gt;In the above example if I enable session cache(this is by default) there is no db query fired at line 9.This is because even though I have cleared the persistence context cache, the  entity is still available in L2 cache. If there are say 1000 clients asking for same  entity, L2 cache clearly saves another 999 trips to db.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;However there is one significant difference when  you obtain an entity from L1 cache and when you get it from L2  cache.&lt;/div&gt; &lt;div&gt;        &lt;span style="font-family:lucida grande;"&gt;Product table = em.find(Product.class,  id);&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-family:lucida grande;"&gt;        Product table1 = em.find(Product.class,  id);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:lucida grande;"&gt;        Product table2 = em.find(Product.class, id);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:lucida grande;"&gt;         System.out.println("Session vs L1 "+(table1==table));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:lucida grande;"&gt;         System.out.println("L1 vs L1 "+(table1==table2));&lt;/span&gt;&lt;br /&gt;&lt;/div&gt; &lt;div style="color: rgb(0, 0, 0); font-family: lucida grande;"&gt;output is&lt;br /&gt;&lt;/div&gt; &lt;div style="color: rgb(0, 0, 153); font-family: times new roman;"&gt;Session vs L1 = true&lt;/div&gt; &lt;div&gt;&lt;span style="color: rgb(0, 0, 153);font-family:lucida grande;" &gt;L1 vs L1 =false&lt;/span&gt;&lt;br /&gt;...&lt;/div&gt;  &lt;div&gt;We can see that the if an entity is given from L1 cache it is given as such, but when it is given from the L2 cache first a clone of entity is created and that clone it is given to client. This means that any  changes made to one entity are not immediately reflected on  the L2 cache. Its only when a unit of work successfully commits  or explicitly calls em.refresh, topLink updates the session  cache.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;   &lt;div&gt;Obviously changes made to an entity obtained by client 1 is not visible to  client 2 as both the clients are operating on different copies of same  entity.  If one is not careful, various parts of the application may be working  on stale data from the session cache. This is where it also becomes absolute  &lt;span&gt;compulsory&lt;/span&gt; for applications to maintain inverse side of relationship.&lt;br /&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt;  &lt;div&gt;Another issue is that if there are say 1000 clients  fetching an entity there will be 1001 copies of the entity in the memory. One in  L2 cache and 1000 in L1 cache , different cloned copy for each entity  manager. If your application is running out of memory, this could be one of the reason. If there are  entities which are very frequently changed it would be better to disable shared cache for them. In toplink you can do  this by specifying a property in your application's persistence.&lt;br /&gt;&lt;span style="font-family:lucida grande;"&gt;&lt;br /&gt;"&amp;lt;property name="toplink.cache.shared.EntityName" value="false" /&amp;gt;"&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;        &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;Since it appears L2 cache will continue to remain in "MSM" it would be  better to analyse its use case in your application.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3328145809638396238-3905713483185008018?l=dumbcuriosity.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dumbcuriosity.blogspot.com/feeds/3905713483185008018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dumbcuriosity.blogspot.com/2007/07/toplink-caching.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3328145809638396238/posts/default/3905713483185008018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3328145809638396238/posts/default/3905713483185008018'/><link rel='alternate' type='text/html' href='http://dumbcuriosity.blogspot.com/2007/07/toplink-caching.html' title='Toplink caching'/><author><name>jitesh</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3328145809638396238.post-8493064360943854998</id><published>2007-07-09T08:59:00.000-07:00</published><updated>2010-04-21T09:38:53.113-07:00</updated><title type='text'>What is in the phrase "Hello World"</title><content type='html'>It was summer of 2001, I was sitting before my brand new Pentium machine, desperately trying to figure out something. Trust me it was not at all fun. Without any doubt that was the most challenging one hour of my life.&lt;br /&gt;&lt;br /&gt;But finally after some hundred useless hits at ctrl+F9, the ugly blue screen was gone and I could see the String "&lt;span style="font-weight: bold;"&gt;Hello World&lt;/span&gt;" blinking bright against the black DOS background.&lt;br /&gt;Yup.. u guessed it right.. It was my first computer program.Oh God !!How delighted I was looking at "Hello World".So much was my pleasure that I didn't even care that I was sitting before a stand alone computer saying Hello World to myself!!&lt;br /&gt;&lt;br /&gt;That time out of some 100 billion English phrases I chose "Hello World" because&lt;br /&gt;&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Mr &lt;a href="http://www.amazon.com/Object-Oriented-Programming-4th-Robert-Lafore/dp/0672323087"&gt;Robert Lafore &lt;/a&gt;asked me to do so.&lt;/li&gt;&lt;li&gt;My intelligent friends typed the same string a day before and my pride would have been deeply hurt if I could not have done the same.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Today 6 years later when I am writing this post I am again choosing this hackneyed string to launch my blog.May be no body will read it, but I can smell the aroma of the same old happiness. This time there are no complex reasons for picking up "Hello World"&lt;br /&gt;This time I just wanted to say&lt;br /&gt;"&lt;span style="font-weight: bold;"&gt;Hello World&lt;/span&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3328145809638396238-8493064360943854998?l=dumbcuriosity.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dumbcuriosity.blogspot.com/feeds/8493064360943854998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dumbcuriosity.blogspot.com/2007/07/what-is-in-phrase-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3328145809638396238/posts/default/8493064360943854998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3328145809638396238/posts/default/8493064360943854998'/><link rel='alternate' type='text/html' href='http://dumbcuriosity.blogspot.com/2007/07/what-is-in-phrase-world.html' title='What is in the phrase &amp;quot;Hello World&amp;quot;'/><author><name>jitesh</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
