Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Java multithreaded interview questions

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the Java multithreaded interview questions". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what Java multithreaded interview questions are.

1: what is a thread?

Lightweight process

2: what are the three parts of a thread?

Processor

Code

data

3: why use multithreading

Make UI respond faster

Using multiprocessor system

Simplified modeling

4: code example: two ways to implement multithreading in Java, including how to define multithreading and how to use multithreading

4.1 implement the Runnable interface

Class Thread1 implements Runnable {public void run () {/ / run generally write a while (true) loop System.out.println (Runnable);}}

4.2 inheriting Thread

Class Thread2 extends Thread {public void run () {System.out.println (extends);}} public class Test {public static void main (String [] a) {Thread1 r = new Thread1 (); Thread T1 = new Thread (r); Thread T2 = new Thread (r); t1.start (); t2.start (); Thread T3 = new Thread2 (); t3.start ();}}

5: how to achieve thread scheduling? How to pause the running of a thread

Wait and notify for dispatching

Sleep ()

6: what is the priority of a thread

Determine which thread executes first

7: briefly describe the functions and differences between sleep method and wait method.

Sleep is to let a thread sleep for a period of time

Wait is to suspend threads.

8: what is a waiting thread

Hide threads running continuously in the background

9: what is the critical resource

Refers to resources shared by multiple threads

10: what is a mutex and how to implement it in Java

The flag used to ensure that only one thread can access critical resources at any one time

Used in front of an object to restrict the execution of a piece of code

Used in a method declaration to indicate that the entire method is a synchronous method.

What is a deadlock? How to avoid it?

If there are multiple threads competing for multiple resources in the program, a deadlock may occur. When a thread waits

A lock held by another thread while the latter is waiting for the lock already held by the first thread

A deadlock occurred.

To avoid deadlocks, you should ensure that when multiple locks are acquired, locks are acquired in the same order in all threads.

Minimize the use of critical resources

12: briefly describe the use of wait and notify,notifyAll

The locked object can call the wait () method, which will cause the current thread to block and discard the object

That is, if the current object of the wait () method is released from the locked state, its other threads will be organic

The object is accessed.

Notify takes a thread on the waiting queue out of the blocking state

NotifyAll takes all threads on the waiting queue out of the blocking state

13: what is url? What is the basic format?

Unified resource locator

Http://www.163.com:port

14: briefly describe the basic functions of IP,Port,TCP

IP stands for network location

Port stands for port number

TCP can ensure that the computers produced by different manufacturers can run in the common network environment, and solve the problem of heterogeneous network communication. It is the basic protocol of network communication at present.

15: a brief description of the basic functions of the Java network model

Describe the connection process between the server and the client

16: what exactly does Java network programming do? How to do it?

1. Establish a connection

two。 Ready to output data, streaming output

3. Streaming input, programming the format required by the business

4. Close the connection

The server assigns a port number. If the customer requests a connection, the server uses the accept () method to open the socket connection.

The customer establishes a connection on the port port of host.

The server and the customer communicate using InputStream and OutputStream.

17: code example: programming based on Socket

Try {ServerSocket s = new ServerSocket (8888); while (true) {Socket S1 = s.accept (); OutputStream os = s1.getOutputStream (); DataOutputStream dos = new DataOutputStream (os); dos.writeUTF ("Hello," + s1.getInetAddress () + "port#" + s1.getPort () + "\ nbye!"); dos.close (); s1.close ();}} catch (IOException e) {System.out.println ("Program error:" + e);}

18: code example: programming based on UDP

The difference between 19:TCP and UDP

TCP can guarantee the integrity and accuracy of the transmitted content, but UDP cannot.

Thank you for your reading, these are the contents of "what are the Java multithreaded interview questions". After the study of this article, I believe you have a deeper understanding of what Java multithreaded interview questions are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report