Update of /cvsroot/freenet/freenet/src/freenet/thread
In directory sc8-pr-cvs1:/tmp/cvs-serv12432
Modified Files:
QThreadFactory.java
Log Message:
Fixed compute bound loop: add logDEBUG,
and add countLock.wait(500) outside loop since
the inner wait is no longer executed when no changes
are required.
Index: QThreadFactory.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/thread/QThreadFactory.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- QThreadFactory.java 26 Sep 2003 12:36:10 -0000 1.34
+++ QThreadFactory.java 27 Sep 2003 07:37:16 -0000 1.35
@@ -37,6 +37,8 @@
private final HeadLock headLock = new HeadLock();
private QThread headerThread = null;
+ private boolean logDEBUG = false;
+
private final Object maxLock = new Object();
private int desiredMax;
/**
@@ -45,6 +47,7 @@
public QThreadFactory(ThreadGroup tg, int desiredMax) {
this.tg = tg;
this.desiredMax = desiredMax;
+ this.logDEBUG = Core.logger.shouldLog(Logger.DEBUG, this);
(new Thread(this, "Thread creation thread.")).start();
}
@@ -52,6 +55,7 @@
while (true) {
Throwable lastEx = null;
int logAvailable = 0, logActive = 0;
+ boolean doLog = false;
try {
int required;
synchronized(countLock) {
@@ -68,6 +72,7 @@
logActive = active;
}
while ( available < required ) {
+ doLog = true;
createThread();
synchronized(countLock) {
// required must not increase.
@@ -92,11 +97,13 @@
logActive = active;
}
}
- Core.logger.log(this,"Thread creation thread past creation loop" +
- ", available: " +
logAvailable +
- ", required: " +
required +
- ", active: " +
logActive,
- Core.logger.DEBUG);
+ if (logDEBUG && doLog)
+ Core.logger.log(this,"Thread creation thread
past creation loop" +
+ ", available:
" + logAvailable +
+ ", required: "
+ required +
+ ", active: " +
logActive,
+
Core.logger.DEBUG);
+ doLog = false;
int allowed;
synchronized(countLock) {
// start with a maximal allowed value.
@@ -112,6 +119,7 @@
logActive = active;
}
while ( available > allowed ) {
+ doLog = true;
destroyThread();
synchronized(countLock) {
// allowed must not decrease.
@@ -136,11 +144,12 @@
logActive = active;
}
}
- Core.logger.log(this,"Thread creation thread past destruction loop" +
- ", available: " +
logAvailable +
- ", allowed: " +
allowed +
- ", active: " +
logActive,
- Core.logger.DEBUG);
+ if (logDEBUG && doLog)
+ Core.logger.log(this,"Thread creation thread
past destruction loop" +
+ ", available:
" + logAvailable +
+ ", allowed: "
+ allowed +
+ ", active: " +
logActive,
+
Core.logger.DEBUG);
} catch (Throwable e) {
if (lastEx == null || !lastEx.getClass().equals(e.getClass()))
@@ -157,9 +166,21 @@
Thread.currentThread().sleep(20); // avoid runaway loop.
} catch (InterruptedException e2) {}
}
+ synchronized(countLock) {
+ try {
+ countLock.wait(500);
+ } catch ( InterruptedException ie ) {}
+ }
}
}
+ /**
+ * @return the target maximum executing jobs
+ * Caller may use this, together with
+ * activeThreads(), to determine load.
+ * This value is decreased by a thread
+ * which dies on out of memory exception.
+ */
public final int maximumThreads() {
synchronized (maxLock) {
return desiredMax;
@@ -340,9 +361,10 @@
}
Core.diagnostics.occurrenceContinuous("jobsPerQThread", jobsDone);
-
- Core.logger.log(this, getName() + " ended. " + available +
- "threads available.", Core.logger.DEBUGGING);
+
+ if (logDEBUG)
+ Core.logger.log(this, getName() + " ended. " +
available +
+ "threads available.",
Core.logger.DEBUG);
}
/**
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs