Thread in java
Before understanding the threads in java lets understand the basics first.
Instruction:Instruction are the command given to computer/processor/central processing unit.Instructions are like copying the data from main memory to register, performing addition, subtraction, division,multiplication.
Instructions are the input to the central processing unit or processor. Processor takes the action depends upon the type of instruction.Set of instruction that processor understand is nothing but the Instruction set of that processor.
example: mov a ,1234;
Program:Set of instruction is nothing but the program.
example: mov a,10
mov b,20
add a,b
Process: Program in execution is nothing but the process.
Suppose you are preparing tea then the recipe of tea is nothing but the program and actually preparing tea by reading the steps one by one is nothing but the process.
Each process will have the separate address space in memory where he stores the local variable value.Each process is having program counter variable to store the value for the the number of instruction executed.
Multitasking:Executing the multiple task at a time is multitasking.
example:While listening music you are writing something in a notebook. You are doing two task at a time is nothing but the multitasking.
Multitasking is achieved by multiprocessing executing more than one process at a time.
One of the drawback/disadvantage is that if there is a requirement of executing two same process at a time then each process will have its saparate address space in a main memory. This problem is addressed by thread we execute same process we called it ad thread of that process and all thread will have the common address space in this way space optimization is achieved.
Multithreading: Executing the more than thread at a time is Multithreading.
Thread: Thread is basically a lightweight sub-process, a smallest unit of processing.Threads of the same process executes in the common address space of that process.