pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedCleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
9+ messages / 9 participants
[nested] [flat]
* Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-06 16:25 Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
0 siblings, 1 reply; 9+ messages in thread
From: Mikko Tiihonen @ 2012-05-06 16:25 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
Here are two small cleanup patches.
First one replaces all Vector references with List (usage) and ArrayList (creation).
Second replaces all Hashtable references with Map (usage) and HashMap (creation).
Reasons:
* Theoretically faster since the ArrayList/HashMap are not synchronized
* Using interfaces makes changing of List/Map implementations easier at later time
* Vector/Hashtable were deprecated already in Java 1.2
-Mikko
Attachments:
0001-Change-all-usages-of-Vector-to-List-and-ArrayList.patch (text/x-patch, 0B) download
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-06 18:03 dmp <danap@ttc-cmc.net>
0 siblings, 3 replies; 9+ messages in thread
From: dmp @ 2012-05-06 18:03 UTC (permalink / raw)
To: pgsql-jdbc
Mikko Tiihonen wrote:
> Hi,
>
> Here are two small cleanup patches.
>
> First one replaces all Vector references with List (usage) and ArrayList
> (creation).
> Second replaces all Hashtable references with Map (usage) and HashMap
> (creation).
>
> Reasons:
> * Theoretically faster since the ArrayList/HashMap are not synchronized
> * Using interfaces makes changing of List/Map implementations easier at
> later time
> * Vector/Hashtable were deprecated already in Java 1.2
My JDK 6 documentation gives no indication that either Vector or Hashtable
as being deprecated. Rather them being retrofitted into the Collectionss
Framework at 1.2. The main difference being that as you said they are
synchronized, which a developer may wish to have for that type of data
structure.
danap.
>
> -Mikko
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-06 19:22 henk de wit <henk53602@hotmail.com>
parent: dmp <danap@ttc-cmc.net>
2 siblings, 0 replies; 9+ messages in thread
From: henk de wit @ 2012-05-06 19:22 UTC (permalink / raw)
To: danap@ttc-cmc.net; pgsql-jdbc
> My JDK 6 documentation gives no indication that either Vector or Hashtable> as being deprecated. Rather them being retrofitted into the Collectionss> Framework at 1.2. The main difference being that as you said they are> synchronized, which a developer may wish to have for that type of data> structure.They were indeed not officially deprecated as some other things in the JDK are, but they were most definitely 'effectively' deprecated. No programmer in his or her right might has used those structures since. =
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-06 19:59 Robin Rosenberg <robin.rosenberg@dewire.com>
parent: dmp <danap@ttc-cmc.net>
2 siblings, 1 reply; 9+ messages in thread
From: Robin Rosenberg @ 2012-05-06 19:59 UTC (permalink / raw)
To: dmp <danap@ttc-cmc.net>; +Cc: pgsql-jdbc
dmp skrev 2012-05-06 20.03:
> Mikko Tiihonen wrote:
> > Hi,
> >
> > Here are two small cleanup patches.
> >
> > First one replaces all Vector references with List (usage) and ArrayList
> > (creation).
> > Second replaces all Hashtable references with Map (usage) and HashMap
> > (creation).
> >
> > Reasons:
> > * Theoretically faster since the ArrayList/HashMap are not synchronized
> > * Using interfaces makes changing of List/Map implementations easier at
> > later time
> > * Vector/Hashtable were deprecated already in Java 1.2
>
> My JDK 6 documentation gives no indication that either Vector or Hashtable
> as being deprecated. Rather them being retrofitted into the Collectionss
> Framework at 1.2. The main difference being that as you said they are
> synchronized, which a developer may wish to have for that type of data
> structure.
They are not deprecated in the "this might go away" sense, but it was discovered
that having self-synchronized collection classes rarely is enough to provide
thread safety, rather synchronization usually has to be handled in a larger
scope than the individual method call. Therefore, if you think Vector makes
your code thread-safe, you need to think again. Even if works it usually a
very expensive way of accomplishing the goal.
-- robin
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-06 20:18 Robin Rosenberg <robin.rosenberg.lists@dewire.com>
parent: dmp <danap@ttc-cmc.net>
2 siblings, 0 replies; 9+ messages in thread
From: Robin Rosenberg @ 2012-05-06 20:18 UTC (permalink / raw)
To: dmp <danap@ttc-cmc.net>; +Cc: pgsql-jdbc
dmp skrev 2012-05-06 20.03:
> Mikko Tiihonen wrote:
> > Hi,
> >
> > Here are two small cleanup patches.
> >
> > First one replaces all Vector references with List (usage) and ArrayList
> > (creation).
> > Second replaces all Hashtable references with Map (usage) and HashMap
> > (creation).
> >
> > Reasons:
> > * Theoretically faster since the ArrayList/HashMap are not synchronized
> > * Using interfaces makes changing of List/Map implementations easier at
> > later time
> > * Vector/Hashtable were deprecated already in Java 1.2
>
> My JDK 6 documentation gives no indication that either Vector or Hashtable
> as being deprecated. Rather them being retrofitted into the Collectionss
> Framework at 1.2. The main difference being that as you said they are
> synchronized, which a developer may wish to have for that type of data
> structure.
They are not deprecated in the "this might go away" sense, but it was discovered
that having self-synchronized collection classes rarely is enough to provide
thread safety, rather synchronization usually has to be handled in a larger
scope than the individual method call. Therefore, if you think Vector makes
your code thread-safe, you need to think again. Even if works it usually a
very expensive way of accomplishing the goal.
-- robin
^ permalink raw reply [nested|flat] 9+ messages in thread
* Fwd: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-06 21:23 Luis Flores <luiscamposflores@gmail.com>
parent: Robin Rosenberg <robin.rosenberg@dewire.com>
0 siblings, 1 reply; 9+ messages in thread
From: Luis Flores @ 2012-05-06 21:23 UTC (permalink / raw)
To: pgsql-jdbc
Some old 1.0 'Collections' (namely Vector and HashTable) where marked
obsolete, they won't disappear beacause they are too widely used, but they
are very inefficient, so they have better alternatives (ArrayList and
HashMap), event if you want an synchronized List or Map you should use
Collections.synchronized[Collection|Map|List|Set] and not use the old
classes.
However same uses of Vector don't work with newer classes, for example, the
method set won't work on ArrayList (ArrayList with size 10 and set at
position 20, you get Exception, on Vector it works).
So, excluding the example above, it is a good thing to replace Vector by
List/ArrayList and Hashtable by Map/HashMap.
In some case LinkedList is better than ArrayList.
Luis Flores
On Sun, May 6, 2012 at 8:59 PM, Robin Rosenberg
<robin.rosenberg@dewire.com>wrote:
> dmp skrev 2012-05-06 20.03:
>
> Mikko Tiihonen wrote:
>> > Hi,
>> >
>> > Here are two small cleanup patches.
>> >
>> > First one replaces all Vector references with List (usage) and
>> ArrayList
>> > (creation).
>> > Second replaces all Hashtable references with Map (usage) and HashMap
>> > (creation).
>> >
>> > Reasons:
>> > * Theoretically faster since the ArrayList/HashMap are not synchronized
>> > * Using interfaces makes changing of List/Map implementations easier at
>> > later time
>> > * Vector/Hashtable were deprecated already in Java 1.2
>>
>> My JDK 6 documentation gives no indication that either Vector or Hashtable
>> as being deprecated. Rather them being retrofitted into the Collectionss
>> Framework at 1.2. The main difference being that as you said they are
>> synchronized, which a developer may wish to have for that type of data
>> structure.
>>
>
> They are not deprecated in the "this might go away" sense, but it was
> discovered
> that having self-synchronized collection classes rarely is enough to
> provide
> thread safety, rather synchronization usually has to be handled in a larger
> scope than the individual method call. Therefore, if you think Vector makes
> your code thread-safe, you need to think again. Even if works it usually a
> very expensive way of accomplishing the goal.
>
> -- robin
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/**mailpref/pgsql-jdbc<http://www.postgresql.org/mailpref/pgsql-jdbc;
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Fwd: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-13 20:44 Lew <noone@lewscanon.com>
parent: Luis Flores <luiscamposflores@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: Lew @ 2012-05-13 20:44 UTC (permalink / raw)
To: pgsql-jdbc
Luis Flores wrote:
> So, excluding the example above, it is a good thing to replace Vector by
> List/ArrayList and Hashtable by Map/HashMap.
> In some case LinkedList is better than ArrayList.
Which is exactly why _usage_ of the list should be through the 'List'
interface regardless of the implementation class.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Fwd: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-13 22:34 Hiroshi Saito <hiroshi@winpg.jp>
0 siblings, 0 replies; 9+ messages in thread
From: Hiroshi Saito @ 2012-05-13 22:34 UTC (permalink / raw)
To: Lew <noone@lewscanon.com>; pgsql-jdbc
Lew <noone@lewscanon.com>:
>Luis Flores wrote:
>> So, excluding the example above, it is a good thing to replace Vector by
>> List/ArrayList and Hashtable by Map/HashMap.
>> In some case LinkedList is better than ArrayList.
>
>Which is exactly why _usage_ of the list should be through the 'List'
>interface regardless of the implementation class.
>
>--
>Lew
>Honi soit qui mal y pense.
>http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
>
>--
>Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-jdbc
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap
@ 2012-05-15 10:25 Dave Cramer <pg@fastcrypt.com>
parent: Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
0 siblings, 0 replies; 9+ messages in thread
From: Dave Cramer @ 2012-05-15 10:25 UTC (permalink / raw)
To: Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>; +Cc: pgsql-jdbc
On Sun, May 6, 2012 at 12:25 PM, Mikko Tiihonen
<mikko.tiihonen@nitorcreations.com> wrote:
> Hi,
>
> Here are two small cleanup patches.
>
> First one replaces all Vector references with List (usage) and ArrayList
> (creation).
> Second replaces all Hashtable references with Map (usage) and HashMap
> (creation).
>
> Reasons:
> * Theoretically faster since the ArrayList/HashMap are not synchronized
> * Using interfaces makes changing of List/Map implementations easier at
> later time
> * Vector/Hashtable were deprecated already in Java 1.2
>
> -Mikko
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
Mikko,
Thanks for the patch it has been applied to master
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2012-05-15 10:25 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-05-06 16:25 Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
2012-05-15 10:25 ` Dave Cramer <pg@fastcrypt.com>
2012-05-06 18:03 Re: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap dmp <danap@ttc-cmc.net>
2012-05-06 19:22 ` henk de wit <henk53602@hotmail.com>
2012-05-06 19:59 ` Robin Rosenberg <robin.rosenberg@dewire.com>
2012-05-06 21:23 ` Luis Flores <luiscamposflores@gmail.com>
2012-05-13 20:44 ` Lew <noone@lewscanon.com>
2012-05-06 20:18 ` Robin Rosenberg <robin.rosenberg.lists@dewire.com>
2012-05-13 22:34 Re: Fwd: Cleanup patch: Change from Vector/Hashtable to ArrayList/HashMap Hiroshi Saito <hiroshi@winpg.jp>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox