Answer Posted / jamshed katta
A lock can be acquired on a class, you would want to do that if you are using static methods in your class, in which case there would be only one copy, so you would need a lock on the class rather than the instance.
Eg:
public static int getPageHits{ // Not synchronized
return hits;
}
so, now instead of using
public static int getPageHits{
synchronized(this){
return hits;
}
}
you would rather do
public static int getPageHits{
synchronized(ClassName.class){
return hits;
}
}
where ClassName is the name of the class whose lock u are trying to acquire.
you could also use Class.forName("ClassName")
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
Give the hierarchy of inputstream and outputstream classes.
What happens if we override only equals?
How big is a gigabyte?
What is difference between overloading and overriding in java?
Draw a UML class diagram for the code fragment given below: public class StringApplet extends Applet { private Label sampleString; private Button showTheString; private ButtonHandler bHandler; private FlowLayout layout; public StringApplet() { sampleString = new Label(" "); showTheString = new Button (" Show the String"); bHandler = new ButtonHandler(); layout = new FlowLayout(); showTheString.addActionListener(bHandler); setLayout(layout); add(sampleString); add(showTheString); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { samplestring.setText("Good Morning"); } } } Note: The methods need not be indicated on the diagram.
How do you define a method?
Is an array a vector?
Should a main method be compulsorily declared in all java classes?
What is JFC?
What is the use of isempty in java?
Can we convert integer to string in java?
State the main difference between c++ and java?
What is isa relationship?
When does a class need a virtual destructor?
What is getkey () in java?