• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • 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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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