implementing runnable versus extending thread

Extending Thread class or implementing Runnable Interface. Which is better?

You have two ways to do so. First, making your class “extends” Thread class.

The other way is making your class implement “Runnable” interface.

The latter is more advantageous, cause when you are going for multiple inheritance, then only interface can help. .

If you are already inheriting a different class, then you have to go for Runnable Interface. Otherwise you can extend Thread class.

Also, if you are implementing interface, it means you have to implement all methods in the interface.

Both Thread class and Runnable interface are provided for convenience and use them as per the requirement.

But if you are not extending any class, better extend Thread class as it will save few lines of coding.

Otherwise performance wise, there is no distinguishable difference. A thread is in the ready state after it has been created and started.

Read more

java persistance in hibernate

Java Persistance With Hibernate

Java Persistence with Hibernate book explores Hibernate by developing an application that ties together hundreds of individual examples. You’ll immediately dig into the rich programming model of Hibernate 3.2 and Java Persistence, working through queries, fetching strategies, caching, transactions, conversations, and more. You’ll also appreciate the well-illustrated discussion of best practices in database design, object/relational mapping, and optimization techniques.

Read more …