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 are the parts of methodology?
What does snprintf return?
What is an object in java and how is it created?
What is Gang of four design patterns
what is recursion in java
How many types of flags are there?
What happens when a thread cannot acquire a lock on an object in java programming?
What is parsing a sentence?
Which list does not allow duplicates in java?
What is covariant return type?
What is boolean strategy?
What are local variables?
How to perform selection sort in java?
If a class is declared without any access modifiers, where may the class be accessed in java programming?
how to split string in java?