Terms of Service Privacy Policy Contact Us



Why Threads?

Threads allow multi-tasking or doing more than one thing at a time. Techincally, if you only have a single processor, there is no such thing as multi-tasking because only one instruction can be processed at a time. But threads allow us to manage software as if it does. With multiple processors - multiple things happen and more than one instruction gets processed. In either event, modern day processors push some 5 kajillion instructions per second (I think it is 5 billion) through the registers. Regardless of your processor situation, Threads allow a class to orchastrate different instruction paths which gives way to better management, if you know what you are doing and that is as simple as learning some Thread theories and lingo

CREATED 2013-01-07 12:12:51.0


UPDATED 2013-01-07 12:16:55.0

Creating Threads...

Here come the examples...

Since I depend heavily on logging instead of a debugger, I have designed my very own logging system that is a lot like Java's logger. I implemented this logger into a base class that I extend called - BaseLogger with all the wrapper methods to perform the logging. For situations where I can't extend BaseLogger, i.e. another class is being extended, I created an interface Logable. To make things even easier, the implementations of all the logging methods defined in Logable are coded into the interface in a comment block. This way, implementing Logable is as simple as cutting and pasting.

Most all classes that I write either extend BaseLogger OR implement Logable. So, when I write a class, I either extend BaseLogger or implement Logable to get my logging.

As with my Logger, Threads can be implemented in one of two ways. Extend the Thread class or implement the Runnable interface. There is no hard and fast rules on which is better, only opinion. Personally I employ the same stratagy that I do for logging. If extending a class already, I implement Runnable, otherwise I extend Thread!

However, in the class library that I use, lds-base.jar, I have a class named ThreadRunner that also extends BaseLogger and implements Runnable. I extend ThreadRunner for almost all Thread classes I write. The big thing about ThreadRunner is it implements thread management helpers that make it easier to track thread status.

CREATED 2013-01-07 12:16:58.0


UPDATED 2013-01-07 12:17:05.0

CREATED 2013-01-08 13:41:15.0


UPDATED 2013-01-08 13:41:15.0


Page Server: Ruger

DBID: db.wam

©2012 Leistware Data Systems

      Hello anonymous