Contents
- 1 Which is better thread or process explain your answer?
- 2 Is it faster to create a thread or a process?
- 3 Do threads use more memory than processes?
- 4 What are process and threads?
- 5 How does flask spawn jobs based on request?
- 6 Why does spring create new thread per request in rest controllers?
- 7 What happens when Windows selects a new thread?
Which is better thread or process explain your answer?
A thread is a lightweight process that can be managed independently by a scheduler. Processes require more time for context switching as they are more heavy. Threads require less time for context switching as they are lighter than processes. Processes are totally independent and don’t share memory.
Is it faster to create a thread or a process?
a process: because very little memory copying is required (just the thread stack), threads are faster to start than processes. The CPU caches and program context can be maintained between threads in a process, rather than being reloaded as in the case of switching a CPU to a different process.
What is the advantage of using threads compared to processes?
Threads are sometimes called lightweight processes because they have their own stack but can access shared data. Because threads share the same address space as the process and other threads within the process, the operational cost of communication between the threads is low, which is an advantage.
Do threads use more memory than processes?
Threads have a shared memory,data,resources,files etc. Threads are created using clone() method. Context switch between the threads are not much time consuming as Process.
What are process and threads?
A process, in the simplest terms, is an executing program. One or more threads run in the context of the process. A thread is the basic unit to which the operating system allocates processor time. A thread can execute any part of the process code, including parts currently being executed by another thread.
What is the downside of processes based concurrency?
The disadvantage of using a process-based model is that it will be slower. You will have to copy data between the concurrent parts of your program. The disadvantage of using a thread-based model is that you will probably get it wrong.
How does flask spawn jobs based on request?
I have a python flask app that waits for requests from user app and than spawns a process with job based on the request it receives. It keeps the status and queue of the jobs in memory. The requests to this service will always have this pattern: I have simply created lists and dicts for the queue, running and finished jobs.
Why does spring create new thread per request in rest controllers?
It’s blocking in the sense that it blocks one thread: the thread taken out of the pool of threads by the servlet container (Tomcat, Jetty, etc., not Spring) to handle your request. Fortunately, many threads are used concurrently to handle requests, otherwise the performance of any Java web application would be dramatic.
Why are scheduling decisions made strictly on a thread basis?
Because scheduling decisions are made strictly on a thread basis, no consideration is given to what process the thread belongs to.
What happens when Windows selects a new thread?
When Windows selects a new thread to run, it performs a context switch to it. A context switch is the procedure of saving the volatile machine state associated with a running thread, loading another thread’s volatile state, and starting the new thread’s execution.