A synchronization wrapper around an un-synchronized map will be slower than a map with
synchronization built-in. So, since Hashtable implements Map, use Hashtable if you
need a synchronized map (and know so ahead-of-time). The key is many situations don't
require a synchronized collection -- in which case HashMap is faster. So go ahead and
use Hashtable, if that's what you need, but use it via the Map interface.
Map m = new HashMap()
can easily be changed to
Map m = new Hashtable()
without affecting the rest of the code. If you put the allocation in a method,
subclasses could alter the choice later. (If the default were HashMap and a subclass
introduced the need for synchronization, for example.)
What to use to back a table depends on what you're doing and what trade-offs you care
to make. I wouldn't use arrays because I find them too restrictive and cumbersome.
On the other hand, if your data is static, or at least of static size, arrays may be a
good choice. It all depends on your needs. I don't think there are any
this-is-always-better-than-that rules. Due to the nature of your question, I'm
assuming that you're creating your own TableModel implementation. If you're just
using DefaultTableModel, most of this is moot. Perhaps the data itself already
provides model and structure?
Joel
-----Original Message-----
From: Greg Munt [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 24, 2001 8:11 AM
To: Jose Antonio Lamas; Ross Burton
Cc: Advanced-Swing
Subject: Re: Array, Vector or Hashtable to keep the table's data model ?
If you need a synchonized map, and dont need nulls permitted, and you
already use Hashtable.. Why would you change?
A synchronized Map can be obtained from the Collections API by using the
java.util.Collections.synchronizedMap(Map) method.
Does Shirazi say why a java.util.Hashtable is faster than a
java.util.Collections.SynchronizedMap?
-----Original Message-----
From: Jose Antonio Lamas <[EMAIL PROTECTED]>
To: Greg Munt <[EMAIL PROTECTED]>; Ross Burton <[EMAIL PROTECTED]>
Cc: Advanced-Swing <[EMAIL PROTECTED]>
Date: Tuesday, July 24, 2001 12:40
Subject: RE: Array, Vector or Hashtable to keep the table's data model ?
>Hi again,
>you suggest migrating Hashtable to Hashmap, but in order to increase
>perfomance that is not very good. As I have read in Jack Shirazi's "Java
>performance tuning", a synchronized Hashmap is slower than a Hashtable
>(which is synchronized). Will the data access improve? I don't think so.
>
>Excerpt of the Java 1.2.2 API: "The HashMap class is roughly equivalent to
>Hashtable, except that it is unsynchronized and permits nulls.".
>
>May I migrate to Hashmap or maintain Hashtable? Suppose I write new code,
>and I need a synchronized Map.
>
>Regards
>
>_______________________________________________
>Advanced-swing mailing list
>[EMAIL PROTECTED]
>http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing