Wednesday, August 18, 2010

Java Best Practices – Vector vs ArrayList vs HashSet

Interesting article on Java ArrayList, Vector and HashSet performance comparison:

Java Code Geeks: Java Best Practices – Vector vs ArrayList vs HashSet

Friday, May 07, 2010

Do NOT write books this way! "Wicket in Action" case.

Copyright (c)
I've been just reading quite a good book on Apache Wicket from Martijn Dashorst and Eelco Hillenius and I got really pissed off at some point. I've always loved "... in Action" series because of its language, attitude to teaching the subject and quality of the material. I've had the same feelings with current book i.e. "Wicket in Action" until page 219 where authors were presenting advanced custom component creation and under one of the listings they wrote: "an elaborate explanation of it (the listing) is outside the scope of this book". WTF?

How can a writer put something like this in his book? If you think the example is too difficult for the scope of current book don't show it at all! You could also redirect readers to the other resources like: "detailed explanation of this concept can be found at ...". But writing "an elaborate explanation of it is outside the scope of this book" is just stupid and frivolous! I pay for the book to have explanations of difficult and complicated subjects - not to read that it's out of the scope (show external resources!).

Anyway, the book is quite good, but more and more examples in the second half of it are getting blur and need more explanations (maybe better metaphor than a bit artificial "lasagne"?)

I hope the authors will make an effort and upgrade the content of this book to the newest Wicket release 1.4.x that introduced Java generics and refactored many classes (e.g. validators).

Monday, April 26, 2010

When multithreading / multitasking your application doesn't help...

Copyright (c) Formula 1
Last week we spotted some behaviors of our system that could be improved significantly. In some specific cases our system is sending multiple independent requests to the underlying subsystems and it is sending them sequentially i.e. is waiting for the first response before sending second request etc.

Monday, March 08, 2010

How to create Mylyn Connector Plugin - part 1

Quite recently I struggled with my company's internal bug tracker, especially lack of Mylyn integration in Eclipse. The easiest way to make it work was just to develop it :) I started with Mylyn/Integrator Reference but as usual Eclipse documentation sucks (I used to develop a lot of SWT/JFace applications and the best documentation I found was outside of Eclipse). It's too short, too shallow and most of all written by/to people who knows Mylyn APIs and architecture quite well. As far as I understand someone who wants just to integrate Mylyn with some bug tracker doesn't have to have this kind of knowledge, but I also understand that Mylyn guys don't really have time for stuff like this.

Anyway, I also found very short tutorial ( explaining in a bit more details how to create Eclipse PDT project etc. But this tutorial doesn't explain all the tiny details that made me spend many hours wondering HTF it should all work together.

In this short series of posts I'll try to give you much simpler tutorial (for morons like me) how to start new Mylyn Connector Plugin even if you're new to Eclipse Plug-in Development. I'll save your time!

OK - let's start. First video shows how to checkout Eclipse Mylyn and Trac packages (only packages required for connector development reference). In all tutorials authors say that you should take Trac Connector as example but they never point to concrete CVS repository and CVSROOT directory. I do:

Second video shows how to create new Mylyn connector project and make it visible in the new Mylyn Connection wizard (I took icons from Trac for simplicity - you can/should use your own). All steps in this tutorial are MANDATORY - if you miss something I'm 99.9% sure it will not work:

Enjoy and stay tuned for more videos in the upcoming weeks...

PS. I used Eclipse 3.5 (Galileo):

Wednesday, February 03, 2010

JavaOne is dead?

I was just looking for the information regarding JavaOne 2010 and found some worrisome blog posts:

Was JavaOne 2009 the last?
JavaOne 2010?
JavaONE 2010? Seems Like It Will Take Place

According to the Moscone Center website JavaOne 2010 is already scheduled between 22nd - 25th of June 2010.

I hope to go there this year! Keep your fingers crossed for my dept's budget :)

Tuesday, February 02, 2010

Memory Leak Protection in Tomcat 7 - fwd

Picture (c) DZone
I'm just forwarding you to a good article on memory leaks protection implementation in the upcoming Apache Tomcat 7.

This article is a in a form of short (but quite comprehensive) interview with:

Mark Thomas, a Senior Software Engineer with SpringSource and committer for Apache Tomcat

Mark points directly to SVN repository where you can actually see how the mechanism he's describing works under the hood.

Mark also mentions about other new features that will be available in new Tomcat 7 (which should be released in alpha in Feb 2010).

Monday, February 01, 2010

How to ensure your IE toolbar buttons are always visible?

Some time ago I encountered a wall while developing add-on for Internet Explorer. I wanted my add-on's button to be always visible after installation process, similarly to delicious stuff.

Problem seems to be quite simple - just check Browser Helper Object's (BHO) options and set some flag (aside of this subject I will tell you that developing pure BHO is a nightmare). In fact there is no such option. Internet Explorer seemed not extensible to this extent. Also finding something in the Internet appeared to be impossible. What the hell? Delicious guys made it!

After quite long searching I was very close to give up and resign from this "feature". But my sixth sense (yes, you should use it a lot while working with Microsoft) was telling me - "check the registry". So I did, and it was a bull's eye shot.

The thing you have to do is to increase the width of Tool Band Width of Internet Explorer (my NSIS script contains this):
WriteRegDWORD HKCU "Software\Microsoft\Internet Explorer\CommandBar" "ToolBandWidth" 800
It's very very primitive but it's the only solution I found to work. You just have to provide the desired width in pixels (decimal value) you'd like IE toolbar to be. Don't worry - you can put there even a value of 3000 - IE is smart enough not to extend the toolbar more than needed i.e. if you put a value of 1000 and your buttons need only 500 pixels IE will automatically adjust toolbar width to 500px.

This solution works but has also a big disadvantage. As you can see I write information to the registry for HKCU (HKEY_CURRENT_USER), so if you are installing the add-on with user Administrator, only this user will have Tool Band enlarged. If you open IE with another user she will probably not see your add-on button(s) (applies to IE7 and IE8).

Until now I couldn't find a better way - did you?

Monday, January 18, 2010

Tomcat 6 Developer's Guide - book review

Picture (c) Packt Publishing
Few days ago I received brand new "Tomcat 6 Developer's Guide" book which I’ll try to review shortly here. The book is best described in few sentences by the author himself:
"While Tomcat is one of the most popular servlet containers, its inner workings still remain a mystery to many developers. If you only have a superficial familiarity of how this container actually functions, much of its power remains untapped and underutilized. [...]"

Before I start let me just mention that I’m experienced Java and Java EE developer and have worked with Tomcat server (with breaks) since version 4.x (year 2003). This means that I know how to develop, deploy, monitor and tune web applications in this web server. I also worked a little bit with Tomcat internals like custom class loaders. Despite that, this book gave me even more information and knowledge. With this book I was able not only to understand how Tomcat works internally but also where and how I could improve it or basically modify internal components for my needs.

Let’s start the review here - first of all I’d like to say that the author Damodar Chetty meets his goals in this book. He states in the preface that this book is not for web developers who want to learn how to write Java Servlet / JSP applications and how to deploy them in Tomcat container. I totally agree with the author – this book will not teach you that. This book is for people who want to know how Tomcat works internally in order to tune it or modify it for specific needs.

The author promises to go deep inside Tomcat’s architecture and implementation in order to better understand what’s under the hood, how it works and how you can improve or monitor it. I can assure you that this goal is met. This book describes in detail also other aspects of Java EE environment that are not directly connected to the Tomcat container but on which its implementation is based.

In this book Damodar Chetty firstly describes Tomcat’s high-level architecture and then breaks them down up to basic Java classes. This way he makes the whole complex architecture easy to understand. The author describes all Tomcat’s components one by one which is reflected in the Table of Contents. I think the author’s intention here was to make the reader read the book from cover to cover. I think so, because if you just want to learn about one particular component it will be a bit difficult to understand all the references to the previous sections. In my opinion this book should be read entirely to make every aspect clear, otherwise you will need to go back in the book and search for previously explained subjects, which is not easy.
This book is definitely component-oriented rather than how-to- or problem-oriented, so if you have a concrete problem or question regarding Tomcat you may have problems finding answer in this book.

All topics are difficult and in my opinion this book is for experienced Java and Java EE developers and administrators. In this field the book fully satisfied me. More so, many topics like "URLs and protocol handlers", "Java class loading" or "Implementing a custom class loader" may be very useful out of the scope of Tomcat server.

What I like in this book’s style is that all, even most complex subjects are explained in a clear way. Every complex component is broken down into pieces that are more easy to explain and understand. This book is also very concise in the source code examples. This makes it more time-consuming to read but on the other hand it forces the reader to understand the subject rather to copy-paste included source code. This aspect again makes this book accessible for experienced developers who know Java and Java EE environments pretty well and are able to start developing their own examples from the textual description.

This book does not promise to cover all the subjects around Tomcat but few of them are really missing in my opinion. Despite full description of how Tomcat is built and how it works I really miss chapters describing how to configure load-balancer for Tomcat or a cluster of Tomcat web servers. I know there are many books or Internet resources that cover these subjects but it would be just nice to have it here. I also realize that load-balancers and clustering components are not core Tomcat components and maybe this is the reason why they are not covered in this book.

To summarize, I think "Tomcat 6 Developer's Guide" book is a really good one and describes Tomcat web server in a pretty detailed fashion. Please note again that you will not learn from this book how to develop web applications using Java Servlet and JSP technologies. You will learn how to effectively use and also modify tomcat internals for you specific needs. You need to be experienced Java / Java EE developer to fully understand all the topics and successfully apply knowledge from this book. I would basically recommend you reading full description of this book available here before buying it.