which of tha following is not a thread safe class?
a) ArrayList b)Vector c)HashTable d)None
Answer Posted / aravinda reddy
ArrayList is by default not thread safe, but we can make it
thread safe. Below is the example how we can make it thread
safe.
public class SynchronizeList {
public static void main(String[] args) {
ArrayList<String> al=new ArrayList<String>
();
al.add("1");
al.add("2");
al.add("3");
//we can make the synchronized
Collections.synchronizedList(al);
synchronized(al) {
Iterator i = al.iterator(); // Must
be in synchronized block
while (i.hasNext())
System.out.println(i.next());
}
}
}
Vector and HashTable are by default synchronized. These are
thread safe.
Hence the answer is ArrayList.
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What do you mean by multithreaded program?
What is the use of protected in java?
What causes memory leak in java?
What is logical variable?
What is meant by stack and queue?
What is string substring?
Is list ordered in java?
Can a lock be acquired on a class in java programming?
What is the difference between access specifiers and access modifiers in java?
Explain garbage collection in java?
Which is the best sorting technique in java?
What does it mean that strings are immutable?
When is the finalize() called?
What does snprintf return?
What access modifiers can be used for methods?