Summary of multi-threaded interview questions (basic)

1. Is the startup of the jvm virtual machine single-threaded or multi-threaded?
Multithreading, because the garbage collection thread must be started first, otherwise it is easy to cause memory overflow. The garbage collection thread and the main thread have two threads, so the startup of the jvm virtual machine is multithreaded.
2. What is the difference between concurrency and parallelism?
Concurrency is running at the same time in the same time period, which is logically simultaneous, such as processing multiple tasks at the same time on a processor.
Parallel is running at the same time at the same time, which is physical simultaneous occurrence, such as multiple processors with multiple tasks at the same time.
3. The difference between thread and process?
A process is the basic unit of system resource scheduling. A running program is a process, and a thread is the execution path of the process.
4. What is a daemon thread?
A daemon thread is a special thread that runs in the background. It is independent of the control terminal and periodically processes tasks or waits for the occurrence of certain events. In Java, the garbage collection thread is a special daemon thread.
5. What are the ways to create threads?
Inherit Thread and rewrite run method;
implement Runnable interface;
implement Callable interface.
6. Tell me about the difference between runnable and callable?
Runnable has no return value, callable can get return value, callable can be regarded as a supplement to runnable.
7. What state does the thread have:
New,
Ready,
Running,
Blocking,
Dead
8. What is the difference between sleep() and wait()?
Sleep() must specify the time, and it will wake up automatically when the time is up. Wait() can wake up through notify() without specifying the time.
The lock will not be released after sleep() is executed, and wait() will release the lock.
sleep() comes from the Thread class, and wait() comes from the obfect class.
9. What is the difference between thread run() and start()?
run(): encapsulates the code executed by the thread, and the direct call is just the call of the ordinary method.
start(): starts the thread, and the run() method is automatically called by the JVM

Guess you like

Origin blog.csdn.net/go_to_study/article/details/109299564