ASF Bugzilla – Attachment 32857 Details for
Bug 51047
Move org.apache.log4j.Category to reentrant read/write locks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
minimal-intrusive patch
c.diff (text/plain), 6.39 KB, created by
mirabilos
on 2015-06-25 20:31:16 UTC
(
hide
)
Description:
minimal-intrusive patch
Filename:
MIME Type:
Creator:
mirabilos
Created:
2015-06-25 20:31:16 UTC
Size:
6.39 KB
patch
obsolete
>--- Category.java.orig 2015-06-25 21:54:15.711516467 +0200 >+++ Category.java 2015-06-25 22:08:11.242167859 +0200 >@@ -42,6 +42,8 @@ import java.util.Enumeration; > import java.util.MissingResourceException; > import java.util.ResourceBundle; > import java.util.Vector; >+import java.util.concurrent.locks.ReadWriteLock; >+import java.util.concurrent.locks.ReentrantReadWriteLock; > > > /** >@@ -117,6 +119,8 @@ public class Category implements Appende > getFQCN method. */ > private static final String FQCN = Category.class.getName(); > >+ private ReadWriteLock lock = new ReentrantReadWriteLock(); >+ > protected ResourceBundle resourceBundle; > > // Categories need to know what Hierarchy they are in >@@ -155,14 +159,18 @@ public class Category implements Appende > <p>If <code>newAppender</code> is already in the list of > appenders, then it won't be added again. > */ >- synchronized > public > void addAppender(Appender newAppender) { >- if(aai == null) { >- aai = new AppenderAttachableImpl(); >+ lock.writeLock().lock(); >+ try { >+ if(aai == null) { >+ aai = new AppenderAttachableImpl(); >+ } >+ aai.addAppender(newAppender); >+ repository.fireAddAppenderEvent(this, newAppender); >+ } finally { >+ lock.writeLock().unlock(); > } >- aai.addAppender(newAppender); >- repository.fireAddAppenderEvent(this, newAppender); > } > > /** >@@ -201,13 +209,16 @@ public class Category implements Appende > > for(Category c = this; c != null; c=c.parent) { > // Protected against simultaneous call to addAppender, removeAppender,... >- synchronized(c) { >- if(c.aai != null) { >- writes += c.aai.appendLoopOnAppenders(event); >- } >- if(!c.additive) { >- break; >- } >+ c.lock.readLock().lock(); >+ try { >+ if(c.aai != null) { >+ writes += c.aai.appendLoopOnAppenders(event); >+ } >+ if(!c.additive) { >+ break; >+ } >+ } finally { >+ c.lock.readLock().unlock(); > } > } > >@@ -221,16 +232,21 @@ public class Category implements Appende > interface. > @since 1.0 > */ >- synchronized > void closeNestedAppenders() { >- Enumeration enumeration = this.getAllAppenders(); >- if(enumeration != null) { >- while(enumeration.hasMoreElements()) { >- Appender a = (Appender) enumeration.nextElement(); >- if(a instanceof AppenderAttachable) { >- a.close(); >- } >+ //XXX shouldn't readLock() be enough? >+ lock.writeLock().lock(); >+ try { >+ Enumeration enumeration = this.getAllAppenders(); >+ if(enumeration != null) { >+ while(enumeration.hasMoreElements()) { >+ Appender a = (Appender) enumeration.nextElement(); >+ if(a instanceof AppenderAttachable) { >+ a.close(); >+ } >+ } > } >+ } finally { >+ lock.writeLock().unlock(); > } > } > >@@ -406,13 +422,17 @@ public class Category implements Appende > is returned. > > @return Enumeration An enumeration of the appenders in this category. */ >- synchronized > public > Enumeration getAllAppenders() { >- if(aai == null) >- return NullEnumeration.getInstance(); >- else >- return aai.getAllAppenders(); >+ lock.readLock().lock(); >+ try { >+ if(aai == null) >+ return NullEnumeration.getInstance(); >+ else >+ return aai.getAllAppenders(); >+ } finally { >+ lock.readLock().unlock(); >+ } > } > > /** >@@ -420,13 +440,17 @@ public class Category implements Appende > > <p>Return the appender with that name if in the list. Return > <code>null</code> otherwise. */ >- synchronized > public > Appender getAppender(String name) { >- if(aai == null || name == null) >- return null; >- >- return aai.getAppender(name); >+ lock.readLock().lock(); >+ try { >+ if(aai == null || name == null) >+ return null; >+ >+ return aai.getAppender(name); >+ } finally { >+ lock.readLock().unlock(); >+ } > } > > /** >@@ -880,19 +904,23 @@ public class Category implements Appende > > <p>This is useful when re-reading configuration information. > */ >- synchronized > public > void removeAllAppenders() { >- if(aai != null) { >- Vector appenders = new Vector(); >- for (Enumeration iter = aai.getAllAppenders(); iter != null && iter.hasMoreElements();) { >- appenders.add(iter.nextElement()); >- } >- aai.removeAllAppenders(); >- for(Enumeration iter = appenders.elements(); iter.hasMoreElements();) { >- fireRemoveAppenderEvent((Appender) iter.nextElement()); >+ lock.writeLock().lock(); >+ try { >+ if(aai != null) { >+ Vector appenders = new Vector(); >+ for (Enumeration iter = aai.getAllAppenders(); iter != null && iter.hasMoreElements();) { >+ appenders.add(iter.nextElement()); >+ } >+ aai.removeAllAppenders(); >+ for(Enumeration iter = appenders.elements(); iter.hasMoreElements();) { >+ fireRemoveAppenderEvent((Appender) iter.nextElement()); >+ } >+ aai = null; > } >- aai = null; >+ } finally { >+ lock.writeLock().unlock(); > } > } > >@@ -902,15 +930,19 @@ public class Category implements Appende > > @since 0.8.2 > */ >- synchronized > public > void removeAppender(Appender appender) { >- if(appender == null || aai == null) >- return; >- boolean wasAttached = aai.isAttached(appender); >- aai.removeAppender(appender); >- if (wasAttached) { >- fireRemoveAppenderEvent(appender); >+ lock.writeLock().lock(); >+ try { >+ if(appender == null || aai == null) >+ return; >+ boolean wasAttached = aai.isAttached(appender); >+ aai.removeAppender(appender); >+ if (wasAttached) { >+ fireRemoveAppenderEvent(appender); >+ } >+ } finally { >+ lock.writeLock().unlock(); > } > } > >@@ -919,14 +951,18 @@ public class Category implements Appende > list of appenders. > > @since 0.8.2 */ >- synchronized > public > void removeAppender(String name) { >- if(name == null || aai == null) return; >- Appender appender = aai.getAppender(name); >- aai.removeAppender(name); >- if (appender != null) { >- fireRemoveAppenderEvent(appender); >+ lock.writeLock().lock(); >+ try { >+ if(name == null || aai == null) return; >+ Appender appender = aai.getAppender(name); >+ aai.removeAppender(name); >+ if (appender != null) { >+ fireRemoveAppenderEvent(appender); >+ } >+ } finally { >+ lock.writeLock().unlock(); > } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 51047
:
26871
| 32857