1. What is the difference between parallelism and concurrency?
Parallel refers to two or more events occurring at the same time; concurrency refers to two or more events occurring at the same time interval.
Parallelism is multiple events on different entities, and concurrency is multiple events on the same entity.
Parallelism is the "simultaneous" processing of multiple tasks on one processor, and concurrency is the simultaneous processing of multiple tasks on multiple processors. Such as hadoop distributed cluster.
So the goal of concurrent programming is to make full use of each core of the processor to achieve the highest processing performance.
(Recommended related video tutorials: java video)
2. What is the difference between threads and processes?
In short, a process is the basic unit for program running and resource allocation. A program has at least one process, and a process has at least one thread. The process has an independent memory unit during execution, and multiple threads share memory resources, reducing the number of switching times and making it more efficient. A thread is an entity of a process, the basic unit of CPU scheduling and dispatch, and a basic unit that is smaller than a program and can run independently. Multiple threads in the same process can execute concurrently.
3. What is the daemon thread?
The daemon thread (daemon thread) is a service thread. To be precise, it serves other threads.
4. What are the ways to create a thread?
(1) Inherit the Thread class to create a thread class
Define a subclass of the Thread class and override the run method of the class. The method body of the run method represents what the thread wants to complete. Task. Therefore, the run() method is called the execution body.
Create an instance of the Thread subclass, that is, create a thread object.
Call the start() method of the thread object to start the thread.
(Recommended tutorial: java introductory program)
(2) Create a thread class through the Runnable interface
Define the implementation class of the runnable interface, and re- Write the run() method of this interface. The method body of the run() method is also the thread execution body of the thread.
Create an instance of the Runnable implementation class, and use this instance as the target of Thread to create a Thread object. This Thread object is the real thread object.
Call the start() method of the thread object to start the thread.
(3) Create a thread through Callable and Future
Create an implementation class of the Callable interface and implement the call() method. The call() method will serve as the thread execution body and have a return value .
Create an instance of the Callable implementation class and use the FutureTask class to wrap the Callable object. The FutureTask object encapsulates the return value of the call() method of the Callable object.
Use the FutureTask object as the target of the Thread object to create and start a new thread.
Call the get() method of the FutureTask object to obtain the return value after the execution of the child thread ends.
5. What is the difference between runnable and callable?
This is a bit of a deep question, and it also shows the breadth of knowledge a Java programmer can acquire.
The return value of the run() method in the Runnable interface is void, and what it does is purely to execute the code in the run() method;
The call() in the Callable interface ) method has a return value and is a generic type. It can be used to obtain the results of asynchronous execution in conjunction with Future and FutureTask.
If you want to know more java interview questions, please pay attention to the java Advanced Interview Questions column.
The above is the detailed content of 2020 New Java Interview Questions - Multithreading (1). For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于PriorityQueue优先级队列的相关知识,Java集合框架中提供了PriorityQueue和PriorityBlockingQueue两种类型的优先级队列,PriorityQueue是线程不安全的,PriorityBlockingQueue是线程安全的,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于java锁的相关问题,包括了独占锁、悲观锁、乐观锁、共享锁等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

封装是一种信息隐藏技术,是指一种将抽象性函式接口的实现细节部分包装、隐藏起来的方法;封装可以被认为是一个保护屏障,防止指定类的代码和数据被外部类定义的代码随机访问。封装可以通过关键字private,protected和public实现。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于设计模式的相关问题,主要将装饰器模式的相关内容,指在不改变现有对象结构的情况下,动态地给该对象增加一些职责的模式,希望对大家有帮助。


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

SublimeText3 Chinese version
Chinese version, very easy to use

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
