Skip to content

Commit e1066a2

Browse files
committed
Merge pull request #33 from jej2003/master
implemented double checked locking for audit manager and implemented interface for audit manager
2 parents 378a982 + 98dc560 commit e1066a2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/main/java/org/audit4j/core/AuditManager.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/**
2929
* The AuditManager. This class is used to submit audit events as well as
30-
* annotations. This is the only audit submition end point of the Audit4j.
30+
* annotations. This is the only audit submission end point of the Audit4j.
3131
*
3232
* @author <a href="mailto:[email protected]">Janith Bandara</a>
3333
*
@@ -42,7 +42,7 @@ private AuditManager() {
4242
}
4343

4444
/** The audit manager. */
45-
private static AuditManager auditManager;
45+
private static volatile AuditManager auditManager;
4646

4747
/**
4848
* Audit.
@@ -98,13 +98,17 @@ public boolean audit(AnnotationAuditEvent annotationEvent) {
9898
* @return single instance of AuditHelper
9999
*/
100100
public static AuditManager getInstance() {
101-
synchronized (AuditManager.class) {
102-
if (auditManager == null) {
103-
Context.init();
104-
auditManager = new AuditManager();
101+
AuditManager result = auditManager;
102+
if(result == null) {
103+
synchronized (AuditManager.class) {
104+
result = auditManager;
105+
if(result == null) {
106+
Context.init();
107+
auditManager = result = new AuditManager();
108+
}
105109
}
106110
}
107-
return auditManager;
111+
return result;
108112
}
109113

110114
/**

0 commit comments

Comments
 (0)