Author: nextgens
Date: 2008-02-16 01:57:18 +0000 (Sat, 16 Feb 2008)
New Revision: 17970
Modified:
trunk/freenet/src/freenet/support/PooledExecutor.java
Log:
synchronization: maybe fix the following exception:
INFO | jvm 1 | 2008/02/16 02:44:54 | Error in WrapperListener.start
callback. java.lang.ArrayIndexOutOfBoundsException: 10
INFO | jvm 1 | 2008/02/16 02:44:54 |
java.lang.ArrayIndexOutOfBoundsException: 10
INFO | jvm 1 | 2008/02/16 02:44:54 | at
freenet.support.PooledExecutor.execute(PooledExecutor.java:61)
INFO | jvm 1 | 2008/02/16 02:44:54 | at
freenet.io.comm.UdpSocketHandler.start(UdpSocketHandler.java:304)
INFO | jvm 1 | 2008/02/16 02:44:54 | at
freenet.node.NodeCrypto.start(NodeCrypto.java:257)
INFO | jvm 1 | 2008/02/16 02:44:54 | at
freenet.node.Node.start(Node.java:1653)
INFO | jvm 1 | 2008/02/16 02:44:54 | at
freenet.node.NodeStarter.start(NodeStarter.java:158)
Modified: trunk/freenet/src/freenet/support/PooledExecutor.java
===================================================================
--- trunk/freenet/src/freenet/support/PooledExecutor.java 2008-02-16
01:13:31 UTC (rev 17969)
+++ trunk/freenet/src/freenet/support/PooledExecutor.java 2008-02-16
01:57:18 UTC (rev 17970)
@@ -58,21 +58,23 @@
boolean miss = false;
synchronized(this) {
jobCount++;
- if(!waitingThreads[prio].isEmpty()) {
- t = (MyThread)
waitingThreads[prio].remove(waitingThreads[prio].size()-1);
- } else {
- // Must create new thread
- if((!fromTicker) &&
NativeThread.usingNativeCode() && prio < Thread.currentThread().getPriority()) {
- // Run on ticker
- ticker.queueTimedJob(job, 0,
true);
- return;
+ synchronized(waitingThreads) {
+ if(!waitingThreads[prio].isEmpty())
+ t = (MyThread)
waitingThreads[prio].remove(waitingThreads[prio].size() - 1);
+ else {
+ // Must create new thread
+ if((!fromTicker) &&
NativeThread.usingNativeCode() && prio < Thread.currentThread().getPriority()) {
+ // Run on ticker
+
ticker.queueTimedJob(job, 0, true);
+ return;
+ }
+ // Will be coalesced by thread
count listings if we use "@" or "for"
+ t = new MyThread("Pooled thread
awaiting work @" + (threadCounter[prio]), threadCounter[prio], prio,
!fromTicker);
+ threadCounter[prio]++;
+ t.setDaemon(true);
+ mustStart = true;
+ miss = true;
}
- // Will be coalesced by thread count
listings if we use "@" or "for"
- t = new MyThread("Pooled thread
awaiting work @"+(threadCounter[prio]), threadCounter[prio], prio, !fromTicker);
- threadCounter[prio]++;
- t.setDaemon(true);
- mustStart = true;
- miss = true;
}
}
synchronized(t) {
@@ -100,11 +102,13 @@
}
}
- public synchronized int[] waitingThreads() {
- int[] result = new int[waitingThreads.length];
- for(int i=0; i<result.length; i++)
- result[i] = waitingThreads[i].size();
- return result;
+ public int[] waitingThreads() {
+ synchronized(waitingThreads) {
+ int[] result = new int[waitingThreads.length];
+ for(int i = 0; i < result.length; i++)
+ result[i] = waitingThreads[i].size();
+ return result;
+ }
}
class MyThread extends NativeThread {
@@ -132,7 +136,7 @@
}
if(job == null) {
- synchronized(PooledExecutor.this) {
+ synchronized(waitingThreads) {
waitingThreads[nativePriority].add(this);
}
synchronized(this) {
@@ -151,7 +155,7 @@
// execute() won't give
us another job if alive = false
}
}
- synchronized(PooledExecutor.this) {
+ synchronized(waitingThreads) {
waitingThreads[nativePriority].remove(this);
if(!alive) {
runningThreads[nativePriority].remove(this);