Like This Site? 
 
RSS Feed Follow Us 

on Twitter! Be Our Fan!

Using Java Threads

Share this post!
 Vote this!

In a single thread only one piece of work can be actioned at a time, with multiple threads multiple tasks can be actioned at the same time. A thread means two different things:
  • An instance of class java.lang.Thread
  • A thread of execution
An instance of Thread is just a object, it can have variables and methods and lives and dies on the heap, a thread of execution is an individual process (a lightweight process) that has it's own call stack. There is always at least one thread ( the one that calls main( ) ) which is called the main thread. Different JVM's treat threads differently, there is no guarantee that code on one system will work the same on another.
Just as we start from main( ) in an application program we always start from run( ) in a thread instance, you can define and instantiate a thread in one of two ways
  • Extend the java.lang.Thread class
  • Implement the Runnable interface  more...

0 comments:

Post a Comment