Update of /cvsroot/freenet/freenet/src/freenet/thread
In directory sc8-pr-cvs1:/tmp/cvs-serv13618/src/freenet/thread
Modified Files:
QThreadFactory.java
Log Message:
6207:OK, so I was a bit hasty with my last Thread creation thread fix. This one makes
much better use of the pools of available threads and once again allows it to awakened
before it's 1 second runtime if needed.
Index: QThreadFactory.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/thread/QThreadFactory.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- QThreadFactory.java 24 Sep 2003 20:00:04 -0000 1.29
+++ QThreadFactory.java 24 Sep 2003 22:32:37 -0000 1.30
@@ -48,16 +48,18 @@
while (true) {
Throwable lastEx = null;
try {
- int desired=0;
+ int desired=Integer.MAX_VALUE;
while ( true ) {
synchronized(this) {
- if (available < MINIMUM_AVAILABLE_ABS ||
- available < active * MINIMUM_AVAILABLE_RATIO) {
+ if ( desired != Integer.MAX_VALUE ||
+ available <
MINIMUM_AVAILABLE_ABS ||
+ available < active * MINIMUM_AVAILABLE_RATIO ) {
desired =
- Math.max((int) (active * IDEAL_AVAILABLE_RATIO),
- 2 * MINIMUM_AVAILABLE_ABS);
- if ( available < desired ) {
+ Math.min(Math.max((int) (active *
IDEAL_AVAILABLE_RATIO),
+ 2 * MINIMUM_AVAILABLE_ABS),desired);
+ if ( available < desired ||
+ available < active *
MINIMUM_AVAILABLE_RATIO ) {
createThread();
} else break;
} else break;
@@ -66,17 +68,20 @@
Core.logger.log(this,"Thread creation thread past creation loop,
available: " +
available + ", desired: " + desired + ", active: " +
active,
Core.logger.DEBUG);
+ desired=0;
while ( true ) {
synchronized(this) {
- if (available > (3 * MINIMUM_AVAILABLE_ABS) &&
- available > active * MAXIMUM_AVAILABLE_RATIO) {
+ if ( desired != 0 ||
+ ( available > (3 *
MINIMUM_AVAILABLE_ABS) &&
+ available > active * MAXIMUM_AVAILABLE_RATIO ) ) {
desired =
- Math.max((int) (active * IDEAL_AVAILABLE_RATIO),
- 2 * MINIMUM_AVAILABLE_ABS);
+ Math.max(Math.max((int) (active *
IDEAL_AVAILABLE_RATIO),
+ 2 * MINIMUM_AVAILABLE_ABS),desired);
- if ( available > desired ) {
+ if ( available > desired ||
+ available > active *
MAXIMUM_AVAILABLE_RATIO ) {
destroyThread();
} else break;
} else break;
@@ -87,7 +92,9 @@
Core.logger.DEBUG);
try {
- Thread.currentThread().sleep(1000);
+ synchronized(this) {
+ wait(1000);
+ }
} catch (InterruptedException e) {
}
} catch (Throwable e) {
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs