• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

thread safety and collections

I'm using an ArrayList as my JTable data component........first off, is this a good decision?  But that's not my real question.  Since ArrayLists are not threadsafe, which collections are?  Or is it trivial to add this code to an ArrayList?

Thanks,
David
0
lomidien
Asked:
lomidien
  • 6
  • 5
1 Solution
 
CEHJCommented:
>>Or is it trivial to add this code to an ArrayList?

(So yes, it is ;-))
0
 
lomidienAuthor Commented:
CEHJ, is this 1.5 specific?  I'm using 1.4 if it is.  :(  I haven't caught up on boxing so I'm not sure how to interpres Collections<T>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
No. Only the documentation is ;-) You can ignore all the angle-bracketed bits
0
 
lomidienAuthor Commented:
dumb question.

Thanks CEHJ

:)
0
 
lomidienAuthor Commented:
overlapped comments.
0
 
CEHJCommented:
:-)

>>I haven't caught up on boxing so I'm not sure how to interpres Collections<T>

No need to worry about this, but FYI that's to do with generics, not autoboxing
0
 
lomidienAuthor Commented:
private ArrayList resultsData = Collections.synchronizedList(new List());

It's late and I'm blurry-eyed....and I'm overlooking something obvious???  It says that .synchronizedList(java.awt.List) isn't found.......all my imports are fine though.....and i see the method in the api so how it claims it doesn't exist is odd to me.

Thanks,
David
0
 
CEHJCommented:
Wrong way round ;-)

SHould be

 private  List resultsData = Collections.synchronizedList(new ArrayList());
0
 
lomidienAuthor Commented:
Thanks!
0
 
CEHJCommented:
:-)
0
 
aozarovCommented:
The suggested code above will make it Thread safe but the question is do you need it to be Thread safe.
Swing components are not thread safe and all updates to them is done via the AWT event dispatching thread.
There is a performance cost for making something thread safe, so do that only if know that your JTable model (I think)
is going to be modified concurrently (which is probably not such a good idea).
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now