Home > Java > JavaInterview questions > Java multi-threading interview questions multiple choice questions including answers

Java multi-threading interview questions multiple choice questions including answers

(*-*)浩
Release: 2019-11-13 14:40:13
Original
4472 people have browsed it

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");
}
Copy after login

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: D

Analysis: 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: D

Analysis: 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: D

Analysis: 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template