This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Deadlock in java.net.URLClassLoader
- From: Andrew Haley <aph at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: classpath at gnu dot org, java at gcc dot gnu dot org
- Date: Thu, 8 Sep 2005 14:35:53 +0100
- Subject: Re: Deadlock in java.net.URLClassLoader
- References: <17156.31023.613650.956641@zapata.pink><m33bp16f5w.fsf@localhost.localdomain>
Tom Tromey writes:
> >>>>> "Andrew" == Andrew Haley <aph@redhat.com> writes:
>
> Andrew> What happens is that one thread does ClassLoader.loadClass, which is
> Andrew> synchronized on the loader, and then URLClassLoader calls toString(),
> Andrew> which is synchronized on urlloaders.
>
> Another choice would be to simply synchronize on the loader and never
> synchronize on urlloaders. There doesn't seem to be a particular
> advantage to having two different locks here.
Like this?
2005-09-08 Andrew Haley <aph@redhat.com>
* java/net/URLClassLoader.java (addURLImpl): Synchronize on the
loader.
(toString): Likewise.
Index: URLClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLClassLoader.java,v
retrieving revision 1.31
diff -c -2 -p -r1.31 URLClassLoader.java
*** URLClassLoader.java 30 Jun 2005 03:20:02 -0000 1.31
--- URLClassLoader.java 8 Sep 2005 13:32:58 -0000
*************** public class URLClassLoader extends Secu
*** 881,885 ****
private void addURLImpl(URL newUrl)
{
! synchronized (urlloaders)
{
if (newUrl == null)
--- 881,885 ----
private void addURLImpl(URL newUrl)
{
! synchronized (this)
{
if (newUrl == null)
*************** public class URLClassLoader extends Secu
*** 1112,1116 ****
public String toString()
{
! synchronized (urlloaders)
{
if (thisString == null)
--- 1112,1116 ----
public String toString()
{
! synchronized (this)
{
if (thisString == null)
Andrew.