Posts

Showing posts from July, 2010

Java NIO is faster than Java IO for Sockets

Image
Most benchmarks comparing Java IO Sockets and Java NIO SocketChannel, compare these libraries using different threading models. Typcially this is Java IO using dedicated thread(s) for each Socket compared with the a dispatcher model for Java NIO, with non-blocking SocketChannels sharing threads. However, this comparison is using IO and NIO using the same threading model with one decidiated thread per Socket/SocketChannel. The point of this comparision is to say, NIO doesn't have to be slow, its just that threading model which is commonly used with NIO is perhaps more trouble than its worth. For more details, including the source see my wiki page on this topic.

Stupidly long class name or a geeky poem?

In the JRE is a stupidly long class name, only a code generator could produce such a long name. (Which the developer of the code generator never checked I assume) com.sun.java.swing.plaf.nimbus. InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState Or is it a geeky poem burried in the code? InternalFrame InternalFrame Title Pane, Internal Frame Title Pane. Maximize Button Window, Not Focused State. The moral of the story, always check the readability/sanity of generated code.

Memory is cheaper than you think.

Many developers spend time trying to save memory without much thought about how much their time is worth and how much the memory is worth. The occasional Java forum question about how to save a few MB of memory, fails to consider how much money that memory is worth. I have compiled a list of machines sold by a major vendor, by memory in them and included the list price for them. These systems support Windows, Lunix and Java. I have made the assumption that machines wth more memory need more processing power, indicated by the GHz and are only included as they have a baring on the price. In the last column you can see that the cost is about £80 per GB. Given a typical developer costs over £40/h, this suggests it is worh spending about 2 hours to save 1 GB. Sometimes it is worth spending time saving memory. However, how much time is 1 MB worth? About 7 seconds. This is significant because I often otimise my code to save a lot less than 1 MB and I spend more than 7 seconds doing