• Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions during interviews of java programmer.

 
Anton Sotnikov
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!
I am not good of the answering for the question by java programmer position and cos i post some questions here.
1. Who is responsable by execution of threads java machine or operation system. and why?
2. Which is the main purpose of ReentrantLock?
Thank you for reply!!
 
Henry Wong
author
Sheriff
Posts: 22525
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can you tell us what was your answer during the interview?

Henry
 
Anton Sotnikov
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My answers were:
1. Java Machine.
2. ReentrantLock have a relation with condition object like that and if first thread execute oneMethod and second thread twoMethod between them must be consistency. And throught the cond.await(); and cond.signal(); occure communication in sample if one thread must have a pause before second thread works.
 
Henry Wong
author
Sheriff
Posts: 22525
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anton Sotnikov wrote:
1. Who is responsable by execution of threads java machine or operation system. and why?


Anton Sotnikov wrote:
1. Java Machine.


And did you answer the "why" part of the question? Regardless, it is never a good idea to answer any interview question with only one or two words. The purpose of the interview is to establish a discussion. The interviewer is looking into more than just the right or wrong answer. The interviewer is looking into how you think, how you approach the problem, and even your soft skills... etc.


Anyway, to answer the question, this is an implementation detail of the JVM. For most, if not all, modern JVMs, the scheduling of threads is forwarded onto the underlying OS. There were some very old JVMs, which used a user space scheduler, but those JVMs haven't existed for a very long time.

Henry
 
Anton Sotnikov
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And did you answer the "why" part of the question?

cos this code give instruction execute a method in particular thread.
 
Henry Wong
author
Sheriff
Posts: 22525
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anton Sotnikov wrote:
And did you answer the "why" part of the question?

cos this code give instruction execute a method in particular thread.
[CODE NOTE QUOTED]


First, how does code answer questions of "why"? And also, how do you give code during a job interview?

And second, see my previous response again. For most intents and purposes, it is *not* the JVM that schedules threads.

Henry
 
Henry Wong
author
Sheriff
Posts: 22525
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, regarding your second question...

Anton Sotnikov wrote:
2. Which is the main purpose of ReentrantLock?


Anton Sotnikov wrote:
2. ReentrantLock have a relation with condition object like that and if first thread execute oneMethod and second thread twoMethod between them must be consistency. And throught the cond.await(); and cond.signal(); occure communication in sample if one thread must have a pause before second thread works.


While what you stated is technically true. Is a discussion of how to use condition variables, really answer the reason for the main purpose of the ReentrantLock? After all, is that all it does? and how is this better than wait()/notify()?

Henry
 
Anton Sotnikov
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and how is this better than wait()/notify()?

Maybe as alternative way
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would expect a description of the purpose of ReentrantLock to include an explanation of the two parts of its name, reentrant and lock.

Conditions are part of the Lock interface and they are very useful, but the ReentrantLock is more than just a mechanism to use Conditions.
 
Anton Sotnikov
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Conditions are part of the Lock interface and they are very useful, but the ReentrantLock is more than just a mechanism to use Conditions.

What yet more for your opinion?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!