🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17294

How thread-safe is a Vector?

#17294
From: Steve Horsley
Date: Thu, 26 Nov 1998 00:00
20 lines
1290 bytes
I got an unexpected error yesterday - The console for an app I'm doing
suddenly reported an out-of-bounds error in Enumeration.nextElement().

Since the code for that enumeration goes:
	Enumeration enum = requests.elements(); // requests is a Vector
	while(enum.hasMoreElements())
		doSomethingWith(enum.nextElement());
I have to assume that another thread removed an element from the Vector
half-way through this thread's enumeration. Yikes! 

I guess I want to just take a snapshot of the Vector, then enumerate 
that. Would requests.clone() be thread safe, or do I have to synchronize
every bit of code that accesses the Vector explicitly?


Secondly, would that error have killed the thread that was doing the 
enumeration?


Steve.
Technical Details
Message-ID: <365D4BD5.1AC0@cwcom.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,51f3325897926eb9,start
X-Google-Attributes: gidf74b3,public
From: Steve Horsley <steve.horsley@cwcom.co.uk>
Subject: How thread-safe is a Vector?
Date: 1998/11/26
Message-ID: <365D4BD5.1AC0@cwcom.co.uk>
X-Deja-AN: 415873879
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Reply-To: steve.horsley@cwcom.co.uk
Newsgroups: borland.public.jbuilder.java.language