What is busy spin, and why should you use it?Īnswer: Busy spin is known as one of the techniques to wait for events without freeing CPU.Similar to many other concurrency issues, the main way to avoid false sharing is to carefully review your code and supporting your data structure with the size of a cache line. What is defined as false sharing in the context of multithreading?Īnswer: False sharing is known to be one of the familiar performance issues on multi-core systems, whereby each process has a local cache.įalse sharing can be hard to identify since the thread may be retrieving completely different global variables that occur to be fairly close together in memory.Therefore, it is always advised to check the condition in loop before continuing. It is likely that, until the thread gets CPU to start running again, the condition may not hold. How would you call wait() method? Would you use if block or loop, and why?Īnswer: wait() method should always be called in loop.lock stripping, which requires more intricate code and proficiency. Therefore, you would opt for an advanced synchronisation technique, e.g. From the two, which would be easier to write: synchronisation code for ten threads or two threads?Īnswer: Both will have the same level of complexity regarding writing the code because synchronisation is independent of the number of threads, although the choice of synchronisation could be subject to the number of threads because this presents more conflict.Instead, you must rely on an alternative mechanism for thread-safety in that particular case, e.g. If the purpose is to provide memory visibility guarantee for individual indices of the array, volatile is of no practical use for you. However, if several threads are altering particular array elements, there won’t be any happens before assurance provided by the volatile modifier for such modification. Therefore, if one thread changes the reference variable points to another array, which will provide a volatile guarantee. Is it possible to make array volatile in Java?Īnswer: Yes, it is possible to make an array volatile in Java, but only the reference which is pointing to an array, not the whole array. Multithreading, Concurrency, and Thread Basics Questions A recommended book is Java Programming Interview Exposed by Noel Markham.Īs a Java developer, it is worth reading this book to take you through some of the most important topics for Java interview, even if you aren’t specifically interviewing. With Java being around as long as it has, there are some reliable and credible books available to help prepare for Java interviews.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |