WeakHashMap usage and problems
Since a WeakHashMap should not be used as a cache (because its keys will be garbage collected too soon), what is it good for ?
- to keep information about objects without preventing them from being GC’d (according to Scott Vachalek).
Bob Lee tells us that “the most common use case for WHM is to use Class instances as keys” (He also points us to the Google Collections Library).
These comments and other really interesting information can be found at a post titled “Why WeakHashMap Sucks“, by Dr. Cliff Click, Chief JVM Architect of Azul Systems.
But since a SoftHashMap (a Map using SoftReference instead of WeakReference) would be useful as a cache, why has Sun decided to provide a WeakHashMap instead of a SoftHashMap ?
Here we have some more related links:
A ‘reference’ to an old bug
Probably the fact that so few experienced Java developers know about the existence of weak references has to do with the bewildering explanations given in the Javadocs for the WeakHashMap and the java.lang.ref package.
If you agree, I urge you to vote for bug 4478625, which was submitted in 2001-JUL-11, but is still marked as ‘in progress’:
Bug 4478625: Better explanation of WeakReference, SoftReference, WeakHashMap
Global warming or global cooling
An article warns us that global cooling is what we must fear most. Scientists predict that the weakest Schwabe solar cycle of the last 2 centuries may start by 2020.
Maybe we just can’t prevent Earth’s weather from changing…
Vertical selection in Vim
If you need to visually select columns in vim, just type:
^V
Then you can use arrow keys (or other motion commands) to select the text you want.
But maybe you just need to cut the first 43 characters of each line in a file. Although you can do that using Vim, a much simpler way is to use the cut command, as in this example:
cut -c '43-' original.txt > new.txt
There’s a more complete post about vertical selections in the vimrc dissected blog.
For those who don’t know diddly about vim, take a look at these links:
Reducing installed application footprint with compressed executable jars
Though you can significantly reduce the download size of a Java application by applying Pack200 compression to its jars, the installed app size is still the same, since once downloaded, the jars must be expanded.
Wouldn’t it be nice if we could keep all jars tightly compressed even after installing the application ?
(more…)
Using RandomAccessFile to access data which doesn’t come from a local file.
Some libraries and applications rely on a RandomAccessFile instance to process its IO tasks, and thus are usually limited to access data from a local file.
If an application needs to access data from another source (from an SFTP file, an HTTP file, CIFS-accessible file, a file inside a zip, tar, gzip or bzip2 archive, etc), it has to use another algorithm - the process isn’t transparent.
Such application could be benefited by an adapter class providing a “RandomAccessFile” view of arbitrary data sources, allowing it to transparently access data from different sources.
Example: a database server using a RandomAccessFile instance to access its data from a local file would automatically be able to access it from a gzip-compressed file.
(more…)