Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use Java Thread API

Personally I am using high level concurrency abstractions cause they are much easier. Actually I cannot remember the last time I have used a theads. But on the technical interview it is a frequently asked question. And yeah I ask about it too.

Are there any use cases when it is necessary to use low level Thread API instead of Executors/Locks/Latches/etc.?

Is there any reason to discuss low level thread API during the technical interview?

like image 714
Mairbek Khadikov Avatar asked Jan 16 '12 14:01

Mairbek Khadikov


People also ask

What is thread API in Java?

Threading is a process where multiple threads run at the same time to increase the efficiency of the processor. Using the Threading API, you can run a main thread and a worker thread simultaneously in your JavaScript application.

What is a thread and why is it used in Java?

A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently. Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority.

What are the advantages of thread in Java?

Advantages of Thread Use of threads provides concurrency within a process. Efficient communication. It is more economical to create and context switch threads. Threads allow utilization of multiprocessor architectures to a greater scale and efficiency.


1 Answers

Technical interviews are often designed to measure the depth of the candidate's knowledge, not any particular ability. Arguably, there has been no need to implement your own linked lists and binary trees for good 15..20 years, yet the questions asking to implement these data structures routinely come up in technical interviews. A smart candidate should be able to figure out high-level concurrency APIs from a short tutorial and the API docs. You ask about thread primitives to see if the candidate understands what is happening behind the scenes when he or she uses concurrency in general, no matter what API is called.

Personally, when I ask questions about things you'd never use, I do not insist on getting the correct names or the right order of the API method parameters. As long as the candidates are clear on the concept, I do not mind them not remembering the particulars of the specific API.

like image 76
Sergey Kalinichenko Avatar answered Sep 23 '22 13:09

Sergey Kalinichenko