


Java multi-threading interview questions multiple choice questions including answers
1. The running result of the following program () (select one)
public static void main(String[] args) { Thread t=new Thread(){ public void run(){ pong(); } }; t.run(); System.out.println("ping"); } static void pong(){ System.out.println("pong"); }
A. pingpong
B. pongping
C. Both pingpong and pongping are possible
D. Neither output
Answer: B
Analysis : To start a thread, you need to call the start() method, and the t.run() method uses the object name. Analysis: To start the thread, you need to call the start() method, and the t.run() method uses the object name.
2. Which of the following methods can be used to create a runnable class ()
A. public class X implements Runnable{public void run() {……}}
B. public class X extends Thread{public void run() {……}}
C. public class X extends Thread{public int run() {……}}
D. public class Interface
3. In Java multi-threading, please use which of the following methods will not cause the thread to enter the blocking state ()
A. sleep()
B. Suspend()C. wait()
D. yield()
Answer: DAnalysis: yield will cause the thread to enter the ready state
4. Regarding sleep() and wait(), the following incorrect description is ()
A. sleep It is a method of the thread class (Thread), and wait is a method of the Object class
B. Sleep does not release the object lock, and wait gives up the object lockC. Sleep suspends the thread, but the monitoring status remains Keep, it will automatically recover after completion
D. After Wait, it enters the waiting lock pool, and only issues the notify method for this object to acquire the object lock and enter the running state.
Answer: DAnalysis: After the notify method for this object, the object lock is acquired and enters the ready state instead of the running state. In addition, the notifyAll method for this object may also acquire the object lock and enter the ready state instead of the running state
5. Among the following lock mechanisms, thread safety cannot be guaranteed ()
A. Lock
#B. SynchronizedC. Volatile
Answer: C 6. Among the steps described below, the necessary steps to create a process are ()A. The scheduler allocates CPU to the process
B. Create a process control blockC. Allocate memory to the process
D. Allocate file descriptor to the process
Answer: BC 7 .What are the common methods of lock-free programming? ()A. For the counter, you can use atomic addition
B. With only one producer and one consumer, you can achieve lock-free access to the ring buffer (Ring Buffer)C. RCU (Read-Copy-Update), old and new copy switching mechanism, delayed release can be used for old copies
D. CAS (Compare-and-Swap), Such as no lock stack, lock-free queue waiting
Answer: DAnalysis: A Although this method is not very good, it is common
B ProducerConsumerQueue is This, C is used extensively in the linux kernel.
D is essentially optimistic locking, which is very difficult to operate. It is more common to have a single producer and multiple consumers or multiple producers and a single consumer, and it is not easy to encounter ABA problems.
B ProducerConsumerQueue is this, it is everywhere
C It is widely used in the linux kernel
D It is essentially optimistic locking, which is very difficult to operate. . It is more common in the case of single producer and multiple consumers or multiple producers and single consumer, and it is not easy to encounter the ABC problem
The above is the detailed content of Java multi-threading interview questions multiple choice questions including answers. 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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment