Process vs Thread
- Memory Share
- Process has independent memory space while threads share memory.
- As threads share memory with each other, communication between them are easier and this results in importance of exclusive control.
- Context Switch
- Normally, context switching is easier from threads than processes.
Example



Different ways of creating Threads
1. Using custom Thread class

2. Using anonymous class

3. Using Runnable

4. Using ThreadFactory
- Main class that uses Host class can control the detail of Thread creation

5. Using ThreadFactory of Executors
- Just need to update the ThreadFactory definition part from above case

6. Using Executor interface

void execute(Runnable r);- Executor interface has this method which can abstract what to run inside
7. Using ExecutorService interface

ExecutorServiceis a service which can repeatedly callexecute- Unlike
Executorwhich was generating new threads every time,ExecutorServicecan reuse the threads
- Unlike
- AS
ExecutorServicehas threads in the background, it hasshutdown()method which would terminate them


Leave a comment