i using treeset in java hold list of integers:
treeset<integer> num = new treeset<integer>();
since application has multiple threads, want able access synchronously. i'm using collections.synchronizedsortedset(num); , returns collections$sortedset. problem cannot cast treeset- can cast sortedset. cannot change class of num object, must cast treeset.
does know how might otherwise cast collections$sortedset treeset, or method synchronize treeset?
there no such implementation, can make 1 on. extend treeset, , override it's methods synchronized methods.
for example:
public class mysyncedtreeset extends treeset { @override public synchronized boolean isempty() { return super.isempty(); } @override public synchronized boolean contains(object o) { return super.contains(o); } // , same other methods }
Comments
Post a Comment