Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 33249 invoked from network); 5 Dec 2008 09:33:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Dec 2008 09:33:13 -0000 Received: (qmail 66021 invoked by uid 500); 5 Dec 2008 09:33:16 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 64944 invoked by uid 500); 5 Dec 2008 09:33:13 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 64933 invoked by uid 99); 5 Dec 2008 09:33:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Dec 2008 01:33:13 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of rosenberg.leon@googlemail.com designates 74.125.44.153 as permitted sender) Received: from [74.125.44.153] (HELO yx-out-1718.google.com) (74.125.44.153) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Dec 2008 09:31:41 +0000 Received: by yx-out-1718.google.com with SMTP id 4so2316005yxp.54 for ; Fri, 05 Dec 2008 01:32:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=G6PgZWw+ysFg0EJqKTHlk6osDEloQi+epGGjZsYiSEg=; b=t9ADFAhOVyk/q3f4LmjuQf06epubl8WX+pjShGpXZ3qFaSwNR4oRQiqrzjQ/EHwWUI cCPxxDrtb+aY5NRhOflaYA83Nf/jNrL+GHW0zDgjE1PokPz9uXNwMk6dILSSb8U+sa1u P5HgSfFpn3bbXTGflBsMSger52iHanLQowvnk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=MerNr2wTeXWBSbBh9VQLCNy/wrtTyWl5oiLy1rWcf5AiS9vgb0uPpAMuNRJ/UWmssR wu5BrszIhiWPOtTGYuzFIYZKK44rOgbDt6Vll0Zh0v6mlhqvLg3xldqJLF/B4BW5T5JF 5QEH4A1YtZrnHnf4cZeD8528H6sywaCNgRPu8= Received: by 10.100.109.13 with SMTP id h13mr8584972anc.21.1228469538802; Fri, 05 Dec 2008 01:32:18 -0800 (PST) Received: by 10.100.96.20 with HTTP; Fri, 5 Dec 2008 01:32:18 -0800 (PST) Message-ID: <327858f40812050132w2b2ede16v3a03d427d3a4fb28@mail.gmail.com> Date: Fri, 5 Dec 2008 10:32:18 +0100 From: "Leon Rosenberg" To: "Tomcat Users List" Subject: Re: jvm cowardly refuses to print a thread dump In-Reply-To: <4938EB61.5040101@capgemini-sdm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <327858f40812010617h7e39329v390ec6dca4e390a1@mail.gmail.com> <0AAE5AB84B013E45A7B61CB66943C17215A3DCFD11@USEA-EXCH7.na.uis.unisys.com> <6715CF65287F8F408DA109EC03AC6C0D845D92FB18@puma.melandra.net> <327858f40812011004p323be166g5cc893ad4864eb78@mail.gmail.com> <493539A5.8070309@capgemini-sdm.com> <4938EB61.5040101@capgemini-sdm.com> X-Virus-Checked: Checked by ClamAV on apache.org On Fri, Dec 5, 2008 at 9:50 AM, Oliver Schoett wrote: > Martin Gainty wrote: >> >> so the solution is put all updates/inserts to the arraylist into a >> synchronized method? > > You must synchronize all read and write methods, because nothing may run in > parallel with a write method, and so read methods must be prevented from > executing if a write method runs already. > > The only exception is if you can ensure that the ArrayList is read-only at > some point in your program (e. g., after a setup phase). > > Arguing that the size() function cannot loop does not help, because the size > function could be called internally in an infinite loop (this would be > visible in the call stack). Oliver, I'm very sorry but i really don't see your point. The only possible need to synchronize access to ArrayList.size is when you a) access the list from different threads and b) need the result to be exact. Neither was the fact in my original post, in fact, as we already resolved it, the vm was getting out of old gen space and afterwards just behaving weird. In 99% of the cases you don't need to synchronize calls to ArrayList, because usually you will use it in a local scope or single thread. And you definitely don't need to synchronize .size(), the worst thing that can happen is that the result is inaccurate, because another thread just removed or added something (except for reasons stated in first part of the mail). regards Leon --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org