Deadlock in java.net.URLClassLoader
Andrew Haley
aph@redhat.com
Thu Sep 8 14:55:00 GMT 2005
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.
More information about the Java
mailing list