Skip to content

Commit

Permalink
Fix #5632.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jan 11, 2011
1 parent 435b1e3 commit fede688
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions source/ch/cyberduck/core/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
* @version $Id$
Expand All @@ -47,10 +46,11 @@ public static Queue instance() {
}

/**
* One transfer at least is always allowed to run.
* One transfer at least is always allowed to run. Queued accesses for threads blocked
* on insertion or removal, are processed in FIFO order
*/
private ArrayBlockingQueue<Transfer> overflow
= new ArrayBlockingQueue<Transfer>(1);
= new ArrayBlockingQueue<Transfer>(1, true);


/**
Expand All @@ -74,20 +74,14 @@ public void add(final Transfer t) {
if(log.isInfoEnabled()) {
log.info("Queuing:" + t);
}
boolean offer = false;
while(!offer || running.size() >= Preferences.instance().getInteger("queue.maxtransfers")) {
// The maximum number of transfers is already reached
try {
boolean offer = false;
while(!offer || running.size() >= Preferences.instance().getInteger("queue.maxtransfers")) {
if(t.isCanceled()) {
break;
}
// Wait for transfer slot. We don't use ArrayBlockingQueue#put because the
// transer can be canceled while waiting for a slot.
offer = overflow.offer(t, 1, TimeUnit.SECONDS);
if(t.isCanceled()) {
break;
}
}
catch(InterruptedException e) {
log.error(e.getMessage());
// Wait for transfer slot.
offer = overflow.offer(t);
}
if(log.isInfoEnabled()) {
log.info("Released from queue:" + t);
Expand Down

0 comments on commit fede688

Please sign in to comment.