Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is vector capacity in java?

1035


What is the constructor?

989


What is thread count in java?

951


I want to control database connections in my program and want that only one thread should be able to make database connection at a time. How can I implement this logic?

1044


What is method overloading in JAVA? Why is it not present in C ?

1038


Give reasons supporting that string is immutable.

890


What is default exception handling in java?

972


What is runtime locatable code?

1362


What are measurable parameters?

1013


What is character in data type?

919


what is abstract class in Java?

1070


What is a subsequence of a string?

1001


What are the disadvantages of using inner classes?

1059


How can you read an integer value from the keyword when the application is runtime in java? example?

1059


What is java command?

1014