Search Interview Questions
Question: How to make application thread-safe ?
Answer: You should use the word synchronized to mark the critical section of code. You may also use other methods of thread synchronization (see wait(), notify(), notifyAll() etc.
|
|||||||||||
Question: How to make application thread-safe ?
Answer: You should use the word synchronized to mark the critical section of code. You may also use other methods of thread synchronization (see wait(), notify(), notifyAll() etc. Source: CoolInterview.com Using synchronized keyword you can make thread safe application and you can also use wait(), notify(), notifyall(). All these methods are of Object class. Source: CoolInterview.com ![]() ![]() You can also use the ReentrntLock class which implements Lock interface. It has three methods signal(), signalAll() and await() methods for synchronization. This was introduced in JDK 5. Source: CoolInterview.com ![]() ![]() We can implement the interface as SingleThreadModel. Source: CoolInterview.com ![]() ![]() It really not something which can be answered directly without looking at the application which you want to make thread safe. As a matter of fact to make a program thread safe all you need to do is make sure you don't have any data race ( read incosistency across threads for the shared resource ) for the resources which can be accessed by multiple threads at the same point of time. To do that these are the most important steps which needs to be followed ( I may still miss something! ) - ![]() ![]() To make the application thread safe we must use keyword synchronized with the block of code i.e with method Source: CoolInterview.com ![]() ![]() Thread-safe means only one thread con use that code at a particular time. For making thread-safe application you have to write method with synchronized key-word or have to write that piece of code in synchronized block. Source: CoolInterview.com ![]() ![]() If we want to make application thread safe the we have to use synchronized keyword with method. ![]() ![]() In order to make application thread safe,the block(group of statements) or method declared as syncronized using keyword syncronize.There are two ways of syncronizng.One is Object levle Syncronization and other one is Class level Syncronization.. Source: CoolInterview.com ![]() ![]() There are two ways that enables us to make application which is thread safe. ![]() ![]() To make an application thread safe we can use the keyword syncronised. Also we should use class level instance variable when considering multi threaded programming. Source: CoolInterview.com ![]() ![]() If you have the better answer, then send it to us. We will display your answer after the approval Rules to Post Answers in CoolInterview.com:-
|
Related Questions | ||
What is it reflection (introspection) ? Why is reflection possible in the Java language? |
|
|
Why are Java ARchive (JAR) files important? |
|
|
In Java, You can create a String object as: String str = "abc"; & String str = new String("abc"); Why cant a button object be created as : Button bt = "abc" Why is it compulsory to create a button object as: Button bt = new Button("abc"); Why is this not compulsory in String's case? |
|
|
What are the main differences between Java and C++? |
|
|
What are interfaces? |
|
|
How can you achieve Multiple Inheritance in Java? |
|
|
What is the difference between StringBuffer and String class? |
|
|
Describe, in general, how java's garbage collector works? |
|
|
What's the difference between == and equals method? |
|
|
What are abstract classes, abstract methods? |
|
|
How can you force all derived classes to implement a method present in the base class? |
|
|
What is the difference between an Applet and an Application? |
|
|
Java says "write once, run anywhere". What are some ways this isn't quite true? |
|
|
Describe java's security model. |
|
|
What is the difference between a Vector and an Array. Discuss the advantages and disadvantages of both? |
|
|
How many different types of JDBC drivers are present? Discuss them. |
|
|
What does the keyword "synchronize" mean in java. When do you use it? What are the disadvantages of synchronization? |
|
|
What are native methods? How do you use them? |
|
|
What is RMI? |
|
|
What is JDBC? Describe the steps needed to execute a SQL query using JDBC. |
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Java Interview Questions & Answers - Exam Mode / Learning Mode
India News Network |