| View previous topic :: View next topic |
| Author |
Message |
jiten_pappu@yahoo.co.in
Joined: 19 May 2006 Posts: 13
|
Posted: Tue May 30, 2006 4:30 am Post subject: threadsafe |
|
|
hi
what is threadsafe?Is Vector is threadsafe ? |
|
| Back to top |
|
 |
satish_raj_j
Joined: 12 May 2006 Posts: 20 Location: Chennai
|
Posted: Tue May 30, 2006 12:06 pm Post subject: Vector Methods are Sychronized |
|
|
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 |
|
 |
jiten_pappu@yahoo.co.in
Joined: 19 May 2006 Posts: 13
|
Posted: Wed May 31, 2006 4:21 am Post subject: Is Vector threadsafe ? |
|
|
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 |
|
 |
sandipmit
Joined: 18 May 2006 Posts: 12 Location: Banglore
|
Posted: Thu Jun 01, 2006 11:24 am Post subject: Threadsafe mechanism |
|
|
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 |
|
 |
satish_raj_j
Joined: 12 May 2006 Posts: 20 Location: Chennai
|
Posted: Thu Jun 01, 2006 3:24 pm Post subject: Vector methods are synchronized |
|
|
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 |
|
 |
AkilanPaul
Joined: 22 May 2006 Posts: 14
|
Posted: Fri Feb 02, 2007 1:46 am Post subject: when i use Vector and ArrayList? |
|
|
| 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 |
|
 |
|