September 17, 2012 at 6:52 am #1848
Getting started with threads in java
Before getting into java thread you must know the concept of multiprocessing and multiprogramming in programming.
In computer science, multiprocessing is a method by which multiple processes, share common processing resources such as a CPU. With a multiprocessing OS, such as Windows OS, you can simultaneously run multiple applications. Multiprocessing refers to the ability of the OS to quickly switch between each computing task to give the impression the different applications are executing multiple actions simultaneously.
Example of multiprocessing is running the browser, MS words or other application simultaneously in window OS.
Today CPU speeds have increased steadily over time. CPU not only do applications run faster, but OSs can switch between applications more quickly. This provides better overall performance. Many actions can happen at once on a computer, and individual applications can run faster.
Even the CPU become faster today, but the multiprocessor is heavy weight process, and this is only for OS type applications.
Multithreading extends the idea of multiprocessing into applications, so you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing time not only among different applications, but also among each thread within an application.
In a multithreaded program, an example application might be divided into multiple threads.
For example if you use the MS word in Window OS and doing some typing job.
So the running the MS word in window OS is processing, and checking the spellings and checking the grammar while typing in MS word are threads which are running with process.
Multithreading is light weight process, A thread is similar to a separate process, in that it can do job independently of other threads. But it is lightweight, because the OS doesn’t have to give it its own memory space, since it shares memory with the other threads in the process.
Thread in java
In java there are two types of threads.
User thread: The life of user thread doesn’t depend on the parent life.
Daemon thread: The life of daemon of thread depends on the parent life.
In java there is no direct way to create daemon thread, we can define user thread and by using user thread we can create daemon thread. The main thread and garbage collector are two daemon threads in java.
You must be logged in to reply to this topic.