Mar 3, 2010
Rishabh Joshi, a product engineer, a friend and a once in a blue-moon blogger, encountered a requirement to create clones of database objects such that even if their relationships get modified the cloning process remains unaffected. Here is his article and the code he wrote for de-proxying hibernate objects and visiting the entire object tree.
The Requirement:
The business requirement was to get an object from the database, create its copy (or clone it), modify the required fields (through-out the object tree), and save as a new row. An, added requirement was, to be able to specify the fields one wants to clone (again, through-out the object tree) and ignore the rest.
Problems faced:
Simple bean copy would not work for us, because, Read more…
Feb 3, 2010
Integer Cache is an interesting concept in Java 1.5 that I recently discovered while reading a blog post.
Here is a post on another blog that explains the concept of Caching Integer Objects in detail: Integer Cache in JDK1.5.
Jan 28, 2010
If a waiting thread wakes up without notify being called it is called Spurious wakeup.
synchronized (obj) {
while (){
obj.wait();
… // Perform action appropriate to condition
}
}
This is the standard idiom to use wait() method. In above scenario if a notify() is sent by any other thread then the condition will not hold and wait() will be skipped. Consider if there is no while loop and some other thread calls notify before wait() is called by this thread, then it may happen that it could wait forever or till next notify is called.
The javadoc of wait method in JDK 5 has also been updated
A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops.
Src : Effective Java By Joshua Bloch