Current location - Recipe Complete Network - Complete cookbook of home-style dishes - Java programmer technical interview common interview?
Java programmer technical interview common interview?
With the continuous development of the Internet, java development has become the mainstream programming language used by many development engineers. Today, java course training institutions will come together to find out what common technical interview questions are needed for us to understand when interviewing java programmers.

1. What is a thread?

A thread is a small unit that an operating system can schedule operations. It is included in the process and is the actual operation unit in the process. Programmers can use it for multiprocessor programming, and you can use multithreading to speed up computation-intensive tasks. For example, if one thread needs 100 milliseconds to complete a task, then ten threads only need 10 milliseconds to complete this task.

2. What is the difference between a thread and a process?

Threads are subsets of processes. A process can have many threads, and each thread performs different tasks in parallel. Different processes use different memory spaces, and all threads share the same memory space. Each thread has a separate stack memory to store local data.

3. How to implement threads in Java?

There are two ways: the instance of the java.lang.Thread class is a thread, but it needs to call the java.lang.Runnable interface to execute it. Since the thread class itself is the called Runnable interface, you can inherit the java.lang.Thread class or directly call the Runnable interface to override the run () method to realize the thread.

4. What are the different thread life cycles?

When we create a new thread in a Java program, its state is new. When we call the thread's start () method, the state becomes Runnable. The thread scheduler allocates CPU time to threads in the runnable thread pool and tells them to change the state to run. Other threads are waiting, blocking, and dead.

5. What is your understanding of thread priority?

Each thread has a priority. Generally speaking, threads with high priority will have priority at runtime, but it depends on the implementation of thread scheduling, which is OS-dependent. We can define the priority of threads, but this does not guarantee that high-priority threads will execute before low-priority threads. Thread priority is an int variable (from 1 to 10), 1 stands for low priority and 10 stands for high priority.

6. What is deadlock? How to analyze and avoid deadlock?

Deadlock refers to the situation that more than two threads are blocked forever, which requires at least two threads and two resources.

To analyze deadlocks, we need to look at the thread dump of Java applications. We need to find out which threads are blocked and the resources they are waiting for. Each resource has a unique id, through which we can find out which threads already have its object lock.