java interview questions, 15 multithreaded java interview questions and answers

15 multithreaded java interview questions and answers
Java, it can be said completion of the foundation is the real beginning of the interview is successful programmer must undergo step. Answer interview skills are very important, fast and accurate answers, allow the company to create a good impression on you. Here is the interview questions and answer some of the ideas I multithreaded java summarized.
1, there is now T1, T2, T3 three threads, how do you ensure T2 after the implementation of execution in T1, T3 after the implementation of execution in T2?
This question is usually asked thread in the first round or the phone interview stage, the purpose is to detect whether you are familiar with the "join" method. Answer can join methods.
2, interfaces in Java Lock advantage over synchronized block what is? You need to implement an efficient caching, which allows multiple users to read, but only allows a user to write, in order to maintain its integrity, what would you do to achieve it?
lock interface multithreading and concurrent programming biggest advantage is that they provide a lock to read and write, respectively, can meet you write high-performance data structures and obstruction conditional like ConcurrentHashMap. I suggest that you carefully read Locks, since currently it is used extensively for building client-side caching electronic trading systems and trading space before connecting to attend multi-threaded interview.
3, except wait and sleep in java methods?
Usually often asked in a phone interview Java thread interview questions. The biggest difference is wait while waiting to release the lock, and sleep has been holding the lock. Wait typically used for inter-thread interactions, sleep is often used to pause execution.
4, to achieve blocking queue in Java.
This is a relatively tough interview questions multithreaded, it can achieve many purposes. First, it can detect whether a candidate who can actually write programs in Java threads; second, can detect the candidates' understanding of concurrency scenarios, and you can ask a lot of questions based on this. If he is to achieve blocking queue with a wait () and notify () method, you can ask him to use the latest in Java 5 concurrent class to write again.
5, use Java to write code to solve the producer - consumer issues.
Very similar to the above problem, but the problem is more classic, there are times when the interview will ask the following questions. How to solve in Java producer - consumer problem, of course, there are many solutions, I have to share a method implemented by blocking queue.
6, Java programming will lead to a deadlock in the program, you will be how to solve?
This is my favorite interview questions Java threads, deadlocks because even when writing multi-threaded programs is very common, but many candidates who can not write deadlock free code, they are struggling. Just tell them that you have the resources and the N N threads, and you need all the resources to complete an operation. For simplicity here, n is 2 can be replaced, the larger the data will look more complicated problem. By avoiding deadlocks in Java to get more information about the deadlock.
7. What is atomic, atomic operations in what is Java?
Very simple java interview questions thread, the next question is that you need to synchronize an atomic operation.
8, Volatile key in Java What is the role? How to use it? In Java it with synchronized method What is the difference?
Since Java 5 and Java memory model changes, threading issues volatile keyword based more and more popular. Should be ready to answer questions about how to ensure that volatile variable visibility, order and consistency in a concurrent environment.
9. What is a race condition? How do you identify and resolve the competition?
This is a multi-threaded appear in the advanced stages of the interview questions. Most interviewers will ask the nearest competitive conditions you encounter, and how did you solve. Some time they will write simple code, and then let you detect race conditions code.
10, how would you use the thread dump? How would you analyze Thread dump?
In UNIX, you can use kill -3, then thread dump will print log in the windows you can use "CTRL + Break". Very simple and professional thread interview questions, but if he asks you how to analyze it, it will be very tricky, need to seriously consider.
11, why do we call the start () performs the run () method when the method, why can not we call the run () method directly?
This is a very classic multithreaded java interview questions. This is what I have just started writing multithreaded programs confusing time. The answer to this question should be like this, when you call the start () method you will create a new thread, and execute code in the run () method inside. But if you just call the run () method, it does not create a new thread does not perform the calling thread code.
12, Java How do you wake up a blocked thread?
This is a problem on the thread and blocking tricky, it has many solutions. If you encounter a thread blocking IO, and I do not think there is a way to abort the thread. If the thread is blocked because the call to wait (), sleep (), or join () method caused, you can interrupt threads, and to wake it up by throwing InterruptedException.
13. What is the difference in Java CycliBarriar and CountdownLatch?
This thread problem is mainly used to detect whether you are familiar with the JDK5 and contracting. These two differences are CyclicBarrier reusable obstacle has been passed, but CountdownLatch can not be reused.
14, what is an immutable object, write concurrent applications it going to help?
Another multi-threaded classic interview question, not directly related with the thread, but indirectly help a lot. This java interview questions can become very tricky, if he asked you to write an immutable object, or ask you why String is immutable.
15, what common problems you encounter in a multithreaded environment is? How did you solve it?
Multithreading and concurrent programs often have Memory-interface, race conditions, deadlocks, live locks and hunger encounter. The problem is not enough, if you get it wrong, it will be difficult to find and debug. This is the most based on interviews, rather than Java threading issues based on the actual application.
These are some simple interview questions thread, not comprehensive, but hope to help you, more private letter may face questions I get!

Guess you like

Origin blog.51cto.com/14623707/2463485