2020 New Java Interview Questions - Multi-Threading (3)
1. What are the states of the thread pool?
The thread pool has 5 states: Running, ShutDown, Stop, Tidying, and Terminated.
Thread pool state switching frame diagram:
(Video tutorial recommendation: java video)
2. What is the difference between the submit() and execute() methods in the thread pool?
The parameters received are different
submit has a return value, but execute does not
submit facilitates Exception handling
3. How to ensure the safety of multi-threaded operations in java programs?
Thread safety is reflected in three aspects:
Atomicity: Provides mutually exclusive access, only one thread can operate on data at the same time, (atomic, synchronized);
Visibility: One thread's modifications to main memory can be seen by other threads in time, (synchronized, volatile);
Ordering: One thread observes the order of instruction execution in other threads ,Due to instruction reordering, this observation is generally ,disordered (happens-before principle).
(Related tutorial recommendations: java introductory program)
4. What is the principle of upgrading multi-thread locks?
In Java, there are four lock states. The levels from low to high are: stateless lock, biased lock, lightweight lock and heavyweight lock state. These states will change with time. As the competition gradually escalates. Locks can be upgraded but not downgraded.
Illustrated process of lock upgrade:
5. What is a deadlock?
Deadlock refers to a blocking phenomenon caused by two or more processes competing for resources or communicating with each other during execution. Without external force, they will all Unable to proceed. At this time, the system is said to be in a deadlock state or the system has a deadlock. These processes that are always waiting for each other are called deadlock processes.
Recommended tutorial: java interview questions
The above is the detailed content of 2020 New Java Interview Questions - Multi-Threading (3). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools
