More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. Volatile is an instruction that the variables can be accessed by multiple threads and hence shouldn't be cached. As volatile variables are never cached and hence their retrieval cannot be optimized.
Help us improve. Please let us know the company, where you were asked this question :
Ans. A source of possible errors in parallel programming, where one thread can cause an error in another thread by changing some aspect of the state of the program that the second thread is depending on (such as the value of variable).
Help us improve. Please let us know the company, where you were asked this question :
Ans. In First Case , Lock for the synchronized block will be received only if singleton == null whereas in second case every thread will acquire the lock before executing the code.
The problem of synchronization with singleton will only happen when the object has not be instantiated. Once instantiated , the check singleton == null will always generate true and the same object will be returned and hence no problem. First condition will make sure that synchronized access ( acquiring locks ) will only take place if the object has not been created so far.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It means that only 1 thread can access have access to Vector at a time and no parallel access is allowed whereas Array List allows parallel access by multiple threads.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Suspend method is used to suspend thread which can be restarted by using resume() method. stop() is used to stop the thread, it cannot be restarted again.
Help us improve. Please let us know the company, where you were asked this question :
Ans. The goal of a synchronised block is to achieve mutual exclusion i.e at one time, the segment of the code should be executed by single thread only and hence the lock needs to be retrieved before executing the segment and then released.
Help us improve. Please let us know the company, where you were asked this question :
Which keyword is used to provide explicit access of a code block to single thread ?
Transient
Final
Explicit
Synchronized
Q14. Can a lock be acquired on a class? How is it different than the object level lock ?
Ans. Yes, a lock can be acquired on the class. Class level lock is applicable on the whole class and hence on all objects of the class whereas the object level lock is applicable on the respective object.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It's the way for synchronization wherein we can store version information in the table , so that if the same entity is updated by two transactions, the last to commit changes is informed of the conflict, and does not override the other transaction's work.
Help us improve. Please let us know the company, where you were asked this question :
Ans. synchronized is a keyword and a modifier. The synchronized keyword is used to indicate that a method can be accessed exclusively by one thread at a time.
Help us improve. Please let us know the company, where you were asked this question :