Thread (concept papers)

Multithreading
Technical means to achieve concurrent execution of multiple threads on the software or hardware.
 
Advantages :
A computer with multi-threading capabilities of hardware support and because of that it can execute multiple threads at the same time, thereby enhancing the overall processing performance.
 
 
Operating system uses round-robin method to ensure that the plurality of processes / threads executing concurrently so-called concurrent is : macroscopic parallel, serial microscopic .
 
J multithreaded virtual machine ava: by the thread transfer and handover execution time assignment processor mode to achieve.

 
Round-robin method: such as the Executive cpu time of 1 second, to a second level is divided into 100 parts. Then, for each of the three threads of a rapidly switch back and forth.
 
Parallel macro, micro serial :
  • For the macro, on the same time period, three threads are at work;
  • Microscopic, the point in time at some point on, Cpu can only give a thread.
 
 
In a multitasking operating system that supports concurrent execution of processes on the surface. For example, you can listen to music while reading a novel.
But, in fact, these programs are not executed simultaneously.
Because the CPU has a time-sharing mechanism , at each time point can only execute a program, but because the CPU runs very fast, able to switch between different time within a very short process, so giving to execute multiple processes simultaneously a feeling of.
 
 
program?
Stored on the hard drive / disk executable file.
 
process?
Run the program in memory.
That is, each running program is a process, within this process includes multiple execution units, and each unit is to perform a thread, and each process includes at least one thread.
 
When a Java program starts, it will have a process. This process will create a default thread, called the main thread.
Runs on the main thread code that main () method.
代码按照顺序 依次调用的程序,称为单线程程序
若希望程序中 ,实现多段程序代码 交替执行的效果,则需要创建多线程程序
多线程程序在运行时,每个线程之间都是独立的,它们可以并发执行,这里的并发是相对的,也就是 说看起来是同时执行的,而实际上和进程一样,也是由CPU轮流调度的。
 
 
 
 
 
多进程 目前主流的操作系统几乎都支持进程并发执行。
优点 提供多进程是为了让操作系统同时执行多个任务
缺点: 进程是重量级的,新建进程对系统的资源消耗比较大。
 
线程【指进程内部的程序流】
线程是轻量级的,新建线程对系统的资源消耗比较小,通常会共享所在进程的资源,以后的主流开发都采用多线程技术。
 
多线程技术 优点: 既能节省空间,系统资源。还能同时执行多个任务。
 
 
 
Java中只有 多线程技术! 没有多进程技术。

Guess you like

Origin www.cnblogs.com/penguin1024/p/11762091.html