Code example for LinkedBlockingQueue

0
package net.wigle.wigleandroid; 
 
import java.util.concurrent.BlockingQueue; 
import java.util.concurrent.LinkedBlockingQueue; 
import java.util.concurrent.atomic.AtomicBoolean; 
 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
 
public class QueryThread extends Thread {
  private final BlockingQueue<Request> queue = new LinkedBlockingQueue<Request>();
  private final AtomicBoolean done = new AtomicBoolean( false );
  private final DatabaseHelper dbHelper;
   
  public interface ResultHandler { 
    public void handleRow( Cursor cursor );
    public void complete(); 
  } 
  public static class Request { 
    private final String sql;
    private final ResultHandler handler;
     
    public Request( final String sql, final ResultHandler handler ) {
      if ( sql == null ) {
        throw new IllegalArgumentException( "sql is null" );
      }