简体   繁体   中英

What's difference between request's thread and program's thread?

I'm almost new to Java. I know multithreading is the action of separating program into several tasks so that they can run concurrently. I have two problems with this concepts.

First of all, it's been said that application server creates a thread per each request. I can't associate this per-request-thread with program's threads. Suppose a program in which there are 5 threads to do things concurrently. How that single thread per request is going to deal with the 5 threads of that program?

Secondly, I have problem grasping the idea of thread pool. Is it about the threads that application server creates per request or it's regarding programs's threads that do tasks concurrently?

I have problem grasping the idea of thread pool.

A simple thread pool is a collection of running threads (aka, worker threads) in which, each thread continually tries to take a task object from a BlockingQueue , and when it gets one, it executes the task, and then goes back to the queue to wait for another one.

A task is an object with some well-known method that the worker calls in order to "execute" the task. Eg, in the thread pools defined by the Java standard library, task objects either are Runnable instances or Callable instances, and the worker executes a task by calling task.run() or by task.call() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM