Index: src/java/org/apache/nutch/fetcher/Fetcher.java
===================================================================
--- src/java/org/apache/nutch/fetcher/Fetcher.java	(revision 1296763)
+++ src/java/org/apache/nutch/fetcher/Fetcher.java	(working copy)
@@ -399,21 +399,57 @@
     }
 
     public synchronized FetchItem getFetchItem() {
-      Iterator<Map.Entry<String, FetchItemQueue>> it =
-        queues.entrySet().iterator();
+	Set set=queues.entrySet();
+      //use rejected for maintaining empty queues or for k'th most priority
+      Set<Entry<String,FetchItemQueue>> rejected = new HashSet<Entry<String,FetchItemQueue>>();
+      // reject empty queues
+      Iterator<Map.Entry<String, FetchItemQueue>> it = set.iterator();
       while (it.hasNext()) {
-        FetchItemQueue fiq = it.next().getValue();
-        // reap empty queues
-        if (fiq.getQueueSize() == 0 && fiq.getInProgressSize() == 0) {
-          it.remove();
-          continue;
-        }
-        FetchItem fit = fiq.getFetchItem();
-        if (fit != null) {
-          totalSize.decrementAndGet();
-          return fit;
-        }
+    	  Map.Entry entry = (Map.Entry)it.next();
+          FetchItemQueue fiq = (FetchItemQueue)(entry.getValue());
+          if (fiq.getQueueSize() == 0 && fiq.getInProgressSize() == 0) {
+            rejected.add(entry);
+            continue;
+          }
       }
+
+      //first select 1'st great queue, and then second and ..., until there is a item to select
+      while(it!=null){
+    	  Map.Entry mostPriority = null;
+
+    	  //select most priority queue that not rejected
+          it=set.iterator();
+    	  while(it.hasNext()){
+    		  Map.Entry fie = (Map.Entry)it.next();
+    		  if(mostPriority==null)
+    			  mostPriority=fie;
+    		  else if((FetchItemQueue)mostPriority.getValue()==null)
+    			  mostPriority=fie;
+    		  else if(!rejected.contains(fie)){
+    			  if(((FetchItemQueue)fie.getValue()).getQueueSize()>((FetchItemQueue)mostPriority.getValue()).getQueueSize())
+    				  mostPriority=fie;
+    		  }
+    	  }
+
+    	  //check if mostPriority has a fetchItem, else continue loop
+    	  if(mostPriority!=null){
+    		  
+        	  //add mostPriority to rejected
+    		  rejected.add(mostPriority);
+    		  
+    		  FetchItemQueue fiq=(FetchItemQueue)mostPriority.getValue();
+    		  FetchItem fit = fiq.getFetchItem();
+    		  if (fit != null) {
+    			  totalSize.decrementAndGet();
+    			  return fit;
+    		  }
+    	  }
+    	  else{
+    		  return null;
+    	  }
+      }
       return null;
     }
 
