1. The elements stored in TreeMap are ordered because it uses a red-black binary tree structure as its underlying data structure. The basis for comparison is: (C) A. Node element Entry B. Node element key-value C. Node element key D. None of the above

  2. Regarding processes and threads, which of the following statements is correct? (C) A. Processes and threads are the same concept. B. If there is a process, there must be a thread. C. A process is the smallest unit of resource allocation, and a thread is the smallest unit of CPU time allocation. D. None of the above statements are correct.

  3. The more accurate way to implement multithreading in Java is: (D) A. Inheriting Thread B. Implementing Runnable C. Implementing Callable D. All of the above are correct.

  4. The correct way to start the MyThread thread is: (A) public class MyThread extends Thread { public void run(){...} } A. new MyThread().start(); B. new MyThread().run(); C. new MyThread().sleep(); D. None of the above.

  5. Which of the following is not part of the thread lifecycle? (D) A. New state B. Running state C. Blocked state D. Start state

  6. The solution to the problem of resource sharing between multiple threads is: (C) A. Using synchronized methods B. Allocating different resources to each thread C. Using synchronized code blocks D. All of the above are correct.

  7. Regarding the wait() method, which of the following statements is correct? (A) A. It is a method of the current lock object. B. It is a method of the current thread. C. It pauses the CPU time slice for a specified period. D. None of the above statements are correct.

  8. Which of the following statements is correct regarding sleep() and wait()? (C) A. wait() is a method called by a thread object; sleep() is a method called by a lock object. B. Both wait() and sleep() are methods called by thread objects. C. sleep() is a method called by a thread object; wait() is a method called by a lock object. D. None of the above statements are correct.

  9. Regarding the Thread class and the Runnable interface, which of the following statements is correct? (D) A. Subclasses of Thread need to implement the run() method, while subclasses of Runnable need to override the run() method. B. Subclasses of Thread cannot be used alone, while subclasses of Runnable can be used alone. C. There is no difference between the Thread class and the Runnable interface. D. The Thread class is suitable for scenarios where multiple threads do not share resources, while the Runnable interface is suitable for scenarios where multiple threads share resources.

  10. Which of the following statements is correct regarding the producer-consumer pattern? (D) A. Producers and consumers do not interact directly but communicate through shared resources. B. Producers compete with each other, and consumers compete with each other. C. Producers and consumers have a cooperative relationship. D. All of the above statements are correct.

Java 多线程基础知识问答 - TreeMap、进程、线程、生命周期、同步、wait()、sleep()、Thread、Runnable、生产者-消费者模式

原文地址: https://www.cveoy.top/t/topic/ocvS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录