Simple Java Thread Management (SJT.Mgmt)

Applications without thread management.

Designed for daily trips to the grocery store,  the stylish Pacer was a veritable safety hazard and dropped from production.

Applications with thread management.

Sensible, safe, and functional, with elegance and performance, the Audi A6 is an incredible everyday car.

Sourceforge Javadoc Latest download CVS Tree Installation Testing

Testing. The Importance of being Earnest

The philosophy of development should follow a simple rule: Do not accept code that can not be proved to specifications.

Unlike the mature industries of civil engineering, aerospace, and defence the software development industry behaves as a mere diapered youth. According to statistics, 80% of all software projects go unused. While business and marketing departments make errors and wild assumptions about user requirements, the blame can often fall squarely onto software developers who don't follow a proper quality and assurance, commonly called a Q&A, process. Where there is a Q&A process in a company, it often places too much importance and resources in functionality testing, and completely miss the earlier stage of unit testing, where bugs can be caught and fixed at a cheaper cost. Unit, load, and functionality testing comprise a full and true Q&A process.

Hats off to gaming companies for probably the best Q&A process in the business, albeit one focused on functionality testing. Their rigourous testing department points out the irony in business' lax attitude when spending $millions on defective Enterprise Applications, opposed to teenagers vigorous demand for perfect $50 Nintendo and PS2 entertainment games. Is it business casual day again!

Following are three common types of testing.

Unit testing

The developer himself will write unit tests first in order to break code he will later write. The approach here is akin to the Null Hypothesis in statistics. Assume the code doesn't work, until it passes all the tests. Unit testing is rarely done as it directly points the finger of blame at the development team. When managers stop pointing fingers, and until developers get over their weakness to accept responsibility, unit testing won't be done and software will always go unproven, which means it's worthless.

Junit  is quite likely the best and easiest way of implementing unit testing into the development process. Junit provides a framework for building and keeping one or many unit tests, it's an integral part of Extreme Programming, which is also know as XP. The programmer will think of possible error conditions. All conditions cannot be determined up front, but will be discovered during the other two Q&A steps and added to their unit tests. Focus on the unusual variants such as 0, negatives, and the fringe values NaN, the ones that are never expected but will eventually surface in the future.

Simple example of unit testing using Junit.

Given a function or method with the signature, int add( int x, int y) which at this point has not been written.

Junit uses the assertequals function in order to test boolean equality conditions. assertequals offers overloaded functions for different datatypes. In our example the following conditions will be tested.

assertequals(5, add(2,3) ) //2+3 = 5
less obvious
assertequals( 1, add( 1, 0) ) //1+0 = 1
assertequals( 0, add( 0, 0) ) //0+0 = 0
try reverse order
assertequals(-5, add(-7,2) ) //-7+2=5
assertequals(-5, add(2, -7) ) //2+-7=5.

Load testing

- Load testing consists of pounding your application with client requests. Its intent on finding your performance ceiling. If its a HTTP application you can use very complete tools from Mercury and RadView , open source tools like the excellent  OpenSTA for Windows, and simple command line tools for Unix like the very  basic yet informative httperf. For non HTTP code, write either an iterative loop in your main method or write a basic client application. It's best to avoid running your client and server application on the same CPU; therefore, write a distributed client using RMI, RPC, or CORBA. Once the load testing software scales into more client requests you will discover the maximum performance in terms of response/request time, transactions pers second, and max simultaneous users. Eventually you will also find the critical juncture where the applications collapses or leaks memory. Now is when you introduce profiling to uncover and repair the source of your memory leak(s).

Profiling and optimizing - Although not a pure testing phases, profiling and optimizing fall into the Q&A program. Unless you undertake rigourous load testing you will not undertake profiling. Many people overlook this stage because of the popular phrase, "Premature optimization is the root of all evil." yet profiling can save your @ss by finding potentially disastrous memory leaks. Unlike C, and C++ where memory leaks are a result of missing an explicit call to free or delete, memory leaks in Java comes both from an over abundance of live objects in a system and slow performing code.  Clearly having many and/or heavy weight objects consumes memory and is one place to fix your code. What isn't clear for Java developers coming from a world where you explicitly free objects, slow performing Java code will also impact your memory consumption. While Java's garbage collector is a saving's grace for RAD coding, it's a double-edged sword. The garbage collector must contend for CPU time like all other threads, but it runs in minimum priority. Multiple requests for slow performaning code will swamp the garbage collector. Slow performing code ( using Strings instead of StringBuffer as a simple example) will always inhibit your cleanup process which will in turn impact your memory consumption. In any Enterprise level development process without profiling your Java code you will eventually face a day of reckoning - it may as well be during an integral part of the development process. See Sitraka's JProbe family include JProfile, and Borland's OptimizeIt  as two mature profiling tools.

Functionality testing

- Once the programmer thinks his or her code is upto snuff, then hand it off to the "Q&A department"  Functionality testing involves abusing the interface as if a mindless end user. Any decent software producer will have an excellent functionality testing department, with a strict workflow process in place to catch buggy software and push it back to the programmer. Bug-tracking systems are typically associated with code repositories, as they are intimate with versioning and the release/staging/release sequence. GNATS is an excellent open source bug tracking system linked with CVS code repository, while ClearCase from Rational has bug-tracking capability.

Graciously hosted by: source forge hosted