Six, multi-threaded ~ interview

1. The difference between directly calling the start() method and run() after Java creates a thread

Answer: The main difference between the start and run methods is that when the program calls the start method a new thread will be created, and the code in the run method will run on the new thread, but when you call the run method directly, the program will not No new thread will be created, the code inside the run method will run on the current thread. In most cases calling the run method is a bug or a mistake. Because the caller's original intention is to call the start method to start a new thread, this error can be detected by many static code coverage tools, such as with fingbugs. If you want to run tasks that consume a lot of time, you'd better use the start method , otherwise your main thread will be stuck when you call the run method. Another difference is that once a thread is started, you cannot call the start method of the thread object repeatedly. Calling the start method of an already started thread will report an IllegalStateException, but you can call the run method repeatedly.

2. Common thread pool modes and usage scenarios of different thread pools

3. What will happen if the number of threads in the newFixedThreadPool thread pool reaches the maximum value, the underlying principle.

4. The synchronization problem of communication between multiple threads, the synchronized lock is the object, and there are many specific problems related to synchronization. For example, different methods of the same class have synchronized locks, and whether an object can be accessed at the same time. Or the static constructor of a class plus the effect of the synchronized lock.

5. Understand the meaning of reentrant locks and the difference between ReentrantLock and synchronized

6. Synchronous data structures , such as the source code understanding of concurrentHashMap and the internal implementation principle, why it is synchronous and efficient

7. Understanding and use of keywords for thread-safe operations such as atomicinteger and Volatile

8. Inter-thread communication, wait and notify

9. The use of timed threads

10. Scenario: In a main thread, it is required that a large number of (many, many) sub-threads are executed before the main thread is executed. A variety of ways, considering efficiency.

11. Difference between process and thread

12. What is thread safety? for example

13. Several states of the thread

14. Concurrent, Synchronous Interfaces or Methods

15. Is HashMap thread safe and why is it not? ConcurrentHashMap, thread safety, why is it safe. What is the underlying implementation like.

16. Use of common classes under JUC. An in-depth study of ThreadPool; the use of BlockingQueue. (The difference between take and poll, the difference between put and offer); the implementation of atomic classes.

17. Briefly introduce the situation of multithreading, starting from the establishment of a thread. Then how to control the synchronization process, the methods and structures commonly used by multithreading

18. Understanding of volatile

19. There are several ways to implement multi-threading, how to do multi-thread synchronization, and talk about the methods commonly used in several threads

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326018122&siteId=291194637