/**
*
* Description: Traditional Threading Technology Review.
* <p>
*
* Multithreading mechanism will improve the efficiency of the program running?
*
==============================================
No, it will be slower because CPU resources are limited
Why do you have multi-threaded downloads?
is to snatch server bandwidth
==============================================
Not necessarily, multithreading can not improve the CPU frequency, that is, the number of instructions per unit time can be executed, if it is a single-threaded task,
CPU can only deal with single-threaded, the multi-threaded to deal with, may reduce the efficiency of the operation, such as a person, three tables,
Make a steamed bun at a table, and then go to another table to do it, or just do it on a table fast?
Obviously it's faster to do it on a table, because it takes time to run to the other table, which is the CPU switching thread.
Why use multithreading?
1. Points of concern, separation
2. Improve performance
Example:
There are many factors that affect efficiency, such as waiting for a resource monopoly, a more time-consuming file upload, a file download, or a long chat with a customer.
Establish a connection, if a thread to deal with it is not service too many customers.
Multithreading will improve performance, do more things at the same time, serve more customers
*
* </p>
*/
public class Traditionalthread {/** * @param args */public static void main (string[] args) {/** * written in 1 Th Read thread = new Thread () {//Overwrite the Run method in the thread class @Overridepublic void Run () {while (true) {try {Thread.Sleep (500) ;} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("The current thread object name gets Method 1:" + thread.currentthread (). GetName ());//this represents the current object thread, which is not recommended. It is now very clear who this is System.out.println ("The current thread object name gets Method 2:" + this.getname ());}}; Thread.Start (); *//** * Writing Method 2: Incoming public thread (Runnable target) * New Runnable () {The host that the thread is running * This notation is more of an object-oriented programming Thread thread2 = new Thread (new Runnable () {@Overridepublic void run () {while (true) {try {thread.sleep ()} catch (Int Erruptedexception e) {e.printstacktrace ();} System.out.println ("1:" + thread.currentthread (). GetName ());//This does not represent the current object//system.out.println ("The current thread object name gets Method 2: "+ this.getname ());}}); Thread2.start (); */new Thread (New Runnable () {public void run () {while (true) {try {thread.sleep ()} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("runnable:" + thread.currentthread (). GetName ());}}) {public void Run () {while (true) {try {Thread.Sleep],} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("Thread:" + thread.currentthread (). GetName ());}}. Start ();}
Traditional Threading Technology Review