Home   FAQ   Search   Member   Groups   Register   Profile   Messages   Log in

threadsafe

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    allappforum.com Forum Index -> Java Interview Questions - I ( Use Java Interview Questions - II for new postings)
View previous topic :: View next topic  
Author Message
jiten_pappu@yahoo.co.in



Joined: 19 May 2006
Posts: 13

PostPosted: Tue May 30, 2006 4:30 am    Post subject: threadsafe Reply with quote

hi
what is threadsafe?Is Vector is threadsafe ?
Back to top
View user's profile Send private message
satish_raj_j



Joined: 12 May 2006
Posts: 20
Location: Chennai

PostPosted: Tue May 30, 2006 12:06 pm    Post subject: Vector Methods are Sychronized Reply with quote

Yes .. Vector Methods are Synchronized......

Thread Safe means when multiple threads try to get access on a common object.. It may result in mutual exclusion. So We should be aware of the making the class by thread safe.. by

Making the methods accessing of the object as synchronized....


Array Lists are not synchroni..... But it is synch.. by

Collections.synchronizeList(new Array................)
Back to top
View user's profile Send private message Send e-mail
jiten_pappu@yahoo.co.in



Joined: 19 May 2006
Posts: 13

PostPosted: Wed May 31, 2006 4:21 am    Post subject: Is Vector threadsafe ? Reply with quote

hi Satish
IF vector is threadsafe ,then multiple threads can access its methods.but u r telling that Vector is Synchronised,Which means only one thread can acess it.....how it is possible
thanks
Back to top
View user's profile Send private message
sandipmit



Joined: 18 May 2006
Posts: 12
Location: Banglore

PostPosted: Thu Jun 01, 2006 11:24 am    Post subject: Threadsafe mechanism Reply with quote

Hi
Vector is threasafe as its methods are synchronized.

At any point of time your application have mutiple thread and they all can try out for the method call. Actually each method call involves object in that stuff. So actually object is the one who call the method. Any one thread can call any method using the object.

Now in case of vector as methods are synchronized if any thread is calling any method of the Vector class the current object of the Vector class will go into the monitor, means that object will be locked for a time untill the execution of that method doesn't get over. So if any other thread wants to call any synchronized method of the same object they can't as object is already locked.

I think this will clear your doubts....

Regards

Sandip Dhummad
Back to top
View user's profile Send private message
satish_raj_j



Joined: 12 May 2006
Posts: 20
Location: Chennai

PostPosted: Thu Jun 01, 2006 3:24 pm    Post subject: Vector methods are synchronized Reply with quote

I agree with Sandip

See...

Synchronization is a concept to avoid mutual exclusion..... ie., Atmost one thread will be accessing an object at one time while the others will be waiting. This concept is valid on shared resources ie., in terms of java shared objects.

Think of a (servlet) accessed by multiple clients...

Even hashtable is synchronized... But the question arises where to use arraylist and where to use Vector... And why the arraylist is not synchronized.. Why the Vector methods are synchronized..
Back to top
View user's profile Send private message Send e-mail
AkilanPaul



Joined: 22 May 2006
Posts: 14

PostPosted: Fri Feb 02, 2007 1:46 am    Post subject: when i use Vector and ArrayList? Reply with quote

when you expect your code is accessed by more than one user you can use sychronised data structure (like Vector) other wise use unsynchronised data structure.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    allappforum.com Forum Index -> Java Interview Questions - I ( Use Java Interview Questions - II for new postings) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group