Feb
24
2006
Juixe TechKnow Zenze is now hosted by TextDrive. I moved Juixe TechKnow Zenze to TextDrive because my old hosting solution has been a a little flaky as of late. For the past few years Juixe has been kindly hosted by my comrade in code Vlad. It is sad to move on because I will surely miss the ease of cPanel but I look forward in taking full advantage of TextDrive’s services, including Ruby on Rails, PHP4, PHP5, Subversion, Python and Django, and and soo much more!
no comments | posted in Rant, Ruby, TechKnow
Feb
22
2006
Here are several links that might be useful to you if you are starting off with Ruby on Rails. Here you will find links to free Ruby on Rails hosting, the Ruby programming language, Rails tutorials, and even an online interactive ruby interpreter.
Juixe TechKnow Zenze Ruby Archive
Ruby
Ruby on Rails
Programming Ruby
Building Ruby, Rails, LightTPD, and MySQL on Tiger
Ruby on Rails Wiki
FreeOnRails
Rails Best Practices, Tips and Tricks
RadRails
Top 12 Ruby on Rails Tutorials
Ruby on Rails API
Try Ruby!
no comments | posted in Ruby, TechKnow
Feb
20
2006
Who said that Java does not have memory leaks? In fact I think that is a good question to ask new grads. Everyone knows that Java’s garbage collection will reclaim unreferenced objects. The problems is that some objects are still referenced even when they are no longer needed.
I been working on a memory problem and used OptimizeIt Profiler 5.0 to track it down. The version of OptimizeIt that I am using dates back to 2002 and unfortunately does not support Eclipse. I am almost sure that the latest release of OptimizeIt will support Eclipse. Without sounding too much like a commercial, OptimizeIt really helped in tracking down the static variable at fault.
OptimizeIt has a Heap view of your application. In my situation, the server had at one point 50,000 instances of one class alone. This class was not the root of the memory propblem since the class was small, but it did indicate that whoever held references to so many objects might be a place to start looking.
The Allocation Backtrace view shows where objects where created, I didn’t think this was all too useful. The Allocation Backtrace is pretty detailed and for a server object we created the allocation backtrace started all the way with TCPTransport$ConnectionHandler.run(). Even still, not that useful for what I was doing.
OptimizeIt has a great Instance Reference Graph. This feature was really helpful in tracking down who keeps references to objects thought to be disposed. The Instance Reference Graph breaks down to three tables. One table contains a ‘Reduced reference graph’, which is more of a tree than a graph, that breaks down who is holding references to objects for which you are interested. Once you navigate down the ‘Reduced reference graph’ the ‘Allocation at’ table will display a view that is reminiscent of a stack trace. The ‘Allocation at’ view will show class names and line numbers for which contain references that have references to your object of interest. Using the Instance Reference Graph I was able to narrow down the problem!
The Memory Leak Detector is great because you can create a snapshot of the heap at a moment in time so that you can compare your application’s memory usage at a later point in time. As you run your application, you may save the heap state to compare it with other saved heap states. Between two heap states, you can view the number of objects and re fences created for any class. Select a object instance and you can see a graph of objects that have references to the selected object.
As you can see, Java does have memory leaks! If your application is having memory problems you should look into using a Java profiler to analyze you application in action. I know that NetBeans 5.0 comes with a free NetBeans Profiler. I myself haven’t used NetBeans 5.0 or its NetBeans Profiler so I can’t say much about that. I am using a older version of OptimizeIt which I don’t think Borland will support so I should try to get familiar with NetBeans Profiler.
Using OptimizeIt I was astonished to discover that our application instantiates over 2 million objects from 7,000 classes. Whoa!
1 comment | posted in IDE, Java, Programming, TechKnow
Feb
13
2006
Why are technology books sooo voluminous, they are usually 500 page coffee tables as opposed to a coffee table book. I feel that most of the pertinent information can be condensed to a 40 page manual or how-to cookbook if they remove all the fluff. When dealing with new technology, lets say Struts, a developer already has, or should be assumed to have, adequate knowledge of Java, the internet, and HTML. Not a single page should be dedicated to the history of Java or HTML in a Struts book and such information should be available online. Books that deal with web application frameworks such as Struts or Ruby of Rails all have the same first chapter on the MVC pattern that these frameworks are built on. These books should reference some wiki in the sky for these background concepts and histories. From my experience the installation chapter is always a waste. Most applications are usually double click installation and usually contain a README file. I almost feel that books should ask you, do you know Java, do you know MVC, do you know HTML, if you answer yes to all these then skip to chapter 7! But maybe this is a publishing issue, I am sure there is a certain number of pages and dimensions that a book should have to be priced at a certain price range and be guaranteed a certain shelf space. All I want is less talk (I don’t care for the kayaking allegories Bruce Tate starts his chapters with) and more code. I really want a cross between the O’Reilly cookbook and hacks series. The cookbook series has plenty of code and the hacks show you some really interesting examples.
no comments | posted in Books, Programming, Rant, TechKnow
Feb
11
2006
I recently worked on a defect on a customer site where all the feedback I got from the server was ‘Set Method failed – null.’ The root cause of the defect had little to do with the code the logged this cryptic ‘debug’ message. The root cause was deeper than this; the root cause lied in the bowels of dynamic events that get fired when the ‘Set Method’ gets called. The root cause lied 10 methods down the stack from the point where it was logged. I had no clue as to what code produced what seems to be a NullPointerException. The problem here was not just bad code but bad logs! Log4J provides programmers with a simple API to write debug message that is a prefer way to what some learn in school, the printf method, but I feel that developers often don’t know what to log and even worse how to handle exceptions!! What follows are real live code example, turn away if you are squeamish!!
catch (Exception e) {}
catch (Exception e) {
//
// FIXME: This is not very good exception handling
//
e.printStackTrace();
}
catch (Exception ex) {
logger.warning("Exception occurred::");
}
I have proposed the following motto at work: If you break it you buy it, if you catch it you log it! The point is to log everything you catch but most importantly log the root cause of the exception and not some cryptic ‘exception occurred’ message.
no comments | posted in Java, Programming, TechKnow
Feb
8
2006
For those old skool C/C++ programmers Java 1.5 introduced a new formatting method to the PrintStream class similar to the old C printf function. The sample code below formats a float value to display only two decimal places:
out.printf("$%.2f", 12.3); // $12.30
A friend of mine saw the code above and thought it was a typo. No it is not a typo. The printf method should be familiar to a lot of programmers, it can format integers, floats, string, and data/time objects. The PrintStream printf method is shorthand for the Formatter class. All of the formatting functionality of the pritnf method is made available in the Formatter class. Use the Fromatter class to format strings that are not intended to be written out to a PrintStream but perhaps managed in a a StringBuffer or other objects.
no comments | posted in Java, TechKnow