This is not a pure technology blog. Neither is it a blog which is based on some other concept. Rather this addresses how we can map technology and common sense for better understanding of technology.
I am spending considerable amount of my time in interviewing candidates. The range of candidates goes from a software engineer to a technical architect. I found most of them are inept in concept of synchronization. This is typical answers I got from the interview.
Q: Do you know synchronization in java
A: Yes. It is used to restrict access to a resource. When code enters synchronized block, others won't be able to access the resource.
Q: What is resource
In a synchronized method, it is the method and in a synchronized block, it is the block. When one thread enters the block of code other thread waits for it.
Q: Can two threads access two different synchronized methods of the same object at the same time?
A: Yes
Q: can two threads access same synchronized methods of two objects of the same class at the same time?
A: No. because the method has been blocked by the first thread.
I asked the same set of questions to one interviewee. When I get the repeated wrong answers, I thought of making him learn.
I showed him a pen and said you can write using it, throw it or see it. So what is the class here?
A: Pen (Nouns are classes and verbs are methods)
What are the methods?
A: see, throw, write
Q: What should be synchronized?
A: write and throw (as thread needs exclusive access to the resource)
Q: What is resource here?
A: Pen (the object)
Q: Who are the threads?
A: I am, and you can be another
So he is clear about synchronization, and he is able to explain synchronization as he can throw the pen that he is writing, and can't write or throw a pen I am writing but can see it. He and I can write on two different pens at the same time and write is not the resource but pen is the resource. I think he understood synchronization from that day.
Synchronization is an example, but correlation works much more than that. Correlating application programming and data modeling gave birth to ORM technologies. One who can correlate Business idea with technology provides good technology solutions.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment