Wednesday, July 16, 2008

Advanced use of hash codes

For many purposes, the plain old HashMap and related collections serve their purpose well and you don't need to worry too much about their gory details.

But in some cases, some more advanced hashing-related techniques can help us save memory. In a new section on advanced hashing techniques, we discuss using a BitSet to perform duplicate elimination with a certain degree of error but a significant memory saving. Knowing a little about the statistics of hash codes helps us work out the degree of error involved. For example, with a BitSet taking up around 120K, we can perform duplicate elimination on tens of thousands of strings with a 'false positive' rate of around 2%. This is a technique that I use, for example, in gathering web site statistics, and in similar cases where I want the functionality of a hash map or hash set but can accept a certain degree of error. The technique allows what would otherwise be quite a large amount of data to be 'held in memory', thus significantly reducing database hits, for example.

Have you been using hash codes in an interesting way that I haven't mentioned? If so, I'd be interested to hear.

Sunday, July 6, 2008

The wait/notify mechanism in Java

One of the most commonly viewed articles on the Javamex site is our discussion of the wait/notify mechanism. It appears that this is a particular topic of doubt among developers.

The wait/notify mechanism is essentially used for one thread to "signal" or pass information to another thread. As of Java 5, the new concurrency classes provide more convenient alternatives to many common uses of wait() and notify(). See in particular:
Suggested additions to these discussions are welcome (on this blog), as well as feedback on how well these articles helped you solve your problem.


Welcome to the news and development blog for the Javamex web site. The site contains various resources for new and experienced Java developers.

Announcements about new and upcoming content will be posted to this blog. The blog also serves as a placeholder for comments about particular pages on the site.