java2db

Threads in java ( Multithreading ) with an example



Thread represents a path of execution with in a process. By default the JVM calls the main thread internally to execute a group of statements.We can create/call more threads in the main thread.

Java thread The main thread :

 

Java thread The Two ways to create a our own  java threads :

Threads in java  Create a class that implements Runnable interface:

Threads in java Create a class that extends Thread class:

The same above example derived from Thread class.

 

Threads in java Life Cycle of a java thread :

Java thread

Threads in java Threads are lightweight compared to processes and share the same address space.
Threads in java Threads allow many tasks to be performed simultaneously.
Threads in java Cost of threads intercommunication is relatively low compare to the process intercommunication.




Related Posts :
Thread synchronization (thread safety) in java – example
   [will not be published]



^ <