Java Threads

17 December 2007

A thread is a thread of execution in a program. Java environment has been built around the multithreading model. In fact all Java class libraries have been designed keeping multithreading in mind. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently. If a thread goes off to sleep for some time, the rest of the program does not get affected by this. Similarly, an animation loop can be fired that will not stop the working of rest of the system.

At a point of time a thread can be in any one of the following states – new, ready, running, inactive and finished. A thread enters the new state as soon as it is created. When it is started (by invoking start() method), it is ready to run. The start() method in turn calls the run() method which makes the thread enter the running state. While running, a thread might get blocked because some resource that it requires is not available, or it could be suspended on purpose for some reason (like put off to sleep by the programmer). In such a case the thread enters the state of being inactive. A thread can also be stopped purposely because its time has expired, then it enters the state of ready to run once again.

A thread that is in running state can be stopped once its job has finished. A thread that is ready to run can also be stopped. A thread that is stopped enters the finished state. A thread that is in inactive state can either be resumed, in which case it enters the ready state again, or it can be stopped in which case it enters the finished state.

del.icio.us:Java Threads  digg:Java Threads  spurl:Java Threads  wists:Java Threads  simpy:Java Threads  newsvine:Java Threads  blinklist:Java Threads  furl:Java Threads  reddit:Java Threads  fark:Java Threads  blogmarks:Java Threads  Y!:Java Threads  smarking:Java Threads  magnolia:Java Threads  segnalo:Java Threads  gifttagging:Java Threads

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Java Threads

Leave a Reply