Concurrency and multithreading (a) - Multi-thread basis

  The concept of multi-threading, very close to us, because of the interview, whether written or interviews will certainly be asked, just shades of difference. The work in only some specific scenarios we will use multithreading

Content, and even some developers never use too many threads, so they might very far away. But we always include the company's very common to see an interview request IO, multi-threading, concurrency and other manufacturers in some

Concept, so unless you thought the way to develop technology that would otherwise be necessary to master, is also the basis of Java.

  We always joked, "interview made aircraft carrier, work tighten the screws," This sentence is not wrong, but the environment is such that it does not hurt, can urge you to learn and progress. You can not change the big ring

Territory, can only work hard, which is also your duty as a programmer. Before I saw online said, "always ask some interviews, work never less than what interesting you?", I feel this sentence thieves do

Laugh, really looking for an excuse for their own food, why not ask yourself why not, others will be able to answer it, if you really want to write some day the bottom of things, how do you do, do it when you have to go to Baidu ?

  Recently finished looking for a job, I am technology in general, but to see people write reviews of this interview, is very offensive, can not help but BB a few words.

What is a thread?

  The implementation of a single process for each task is a thread. A thread is the smallest unit of the operation is performed in the process. This is the definition of Baidu, is a thread in Java Thread, start Main function is activated

The main thread.

  Multithreading can make better use of resources such as CPU, provide better and faster response. Multithreading with the benefits, there are certainly bad place. For example thread-safety issues, such as thread context switching overhead.

So we said why Redis can achieve such a high QPS, will say the single-threaded, no thread context switches, simplifying the algorithm and the like.

Thread context switching

  It refers to the storage and restore the CPU state by the program counter thread can resume execution from the interruption point, high efficiency multi-threading, but there are no small thread context switching overhead.

Thread Safety

  Thread-safe multithreaded inevitable thing, mainly for the operation of critical resources, critical resources include: properties, objects, databases, etc. (usually call the method does not consider, because the method is

Execution of the stack, and the stack is private to the thread). So to ensure critical resources to operate only one thread at the same time, achieve the thread mutually exclusive operation mode, for example: synchronized and lock and so on.

Create a thread way

  I am sure you all know this, but the online writing articles, there is that two, three, four, six kinds. . . When the interview to answer some of it in the end, people ignorant force. I know in a course recently bought in

The answer both.

 

Guess you like

Origin www.cnblogs.com/huigelaile/p/11703081.html