title: Android prepare waiting mechanism or correct synchronize to service
body: <p>in my Android project i try to prepare waiting mechanism or correct synchronize to <code>intent service</code> to handle multi concurrency requests user. for example after click on button, my application try to get data on server with <code>Service</code>, </p>
  
  <p>after click on the button, user maybe try to click on that again, for manage this operation i coding below sample to handle multi concurrency requests user, such as waiting to finish request with create an requests path.</p>
  
  <p>but in this code i cont know how to create requests stack, that means they must run by order's requests.</p>
  
  <h1><em>now is my code correct?</em></h1>
  
  <p><strong>Volley Simple Singleton Class:</strong></p>
  
  <pre><code>public class CustomVolleyRequestQueue {
  
      private static CustomVolleyRequestQueue mInstance;
      private static Context                  context;
      private        RequestQueue             mRequestQueue;
  
      private CustomVolleyRequestQueue(Context context) {
          this.context = context;
          mRequestQueue = getRequestQueue();
      }
  
      public static synchronized CustomVolleyRequestQueue getInstance(Context context) {
          if (mInstance == null) {
              mInstance = new CustomVolleyRequestQueue(context);
          }
          return mInstance;
      }
  
      public RequestQueue getRequestQueue() {
          if (mRequestQueue == null) {
              Cache cache = new DiskBasedCache(context.getCacheDir(), 10 * 1024 * 1024);
              Network network = new BasicNetwork(new HurlStack());
              mRequestQueue = new RequestQueue(cache, network);
              // start the volley request queue
              mRequestQueue.start();
          }
          return mRequestQueue;
      }
  }
  </code></pre>
  
  <p><strong>Intent Service:</strong></p>
  
  <pre><code>public class WebService extends IntentService {
      public static final String REQUEST_TAG = "SimpleWebServiceBlockingRequest";
      private RequestQueue mQueue;
      private Object       isReceiveMessagesLock;
  
      public WebService() {
          super("WebService");
      }
  
      public WebService(String name) {
          super("WebService");
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
          if (intent != null) {
              Bundle data = intent.getExtras();
              if (data != null) {
                  String url = data.getString("url");
                  synchronized (isReceiveMessagesLock) {
                      if (isReceiveMessagesLock != null) {
                          return;
                      } else {
                          try {
                              isReceiveMessagesLock.wait();
                              startParsingTask(url); //receiving start
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          }
                      }
                  }
  
              }
          }
      }
  
      public void startParsingTask(final String url) {
          Thread prepaire_request_thread = new Thread() {
              public void run() {
                  ThreadB    request_from_servcer_thread = new ThreadB(getApplicationContext(), url);
                  JSONObject json_object                 = null;
                  try {
                      json_object = request_from_servcer_thread.execute().get(10, TimeUnit.SECONDS);
                  } catch (InterruptedException | ExecutionException | TimeoutException e) {
                      e.printStackTrace();
                  }
                  if (json_object != null) {
                      Log.e("OUTPUT: ", json_object.toString());
                  }
              }
          };
          prepaire_request_thread.start();
      }
  
      private class ThreadB extends AsyncTask&lt;Void, Void, JSONObject&gt; {
          private Context context;
          private String fetch_url = "";
  
          public ThreadB(Context ctx, String url) {
              context = ctx;
              this.fetch_url = url;
          }
  
          @Override
          protected JSONObject doInBackground(Void... params) {
              final RequestFuture&lt;JSONObject&gt; futureRequest = RequestFuture.newFuture();
              mQueue = CustomVolleyRequestQueue.getInstance(context.getApplicationContext())
                      .getRequestQueue();
              final JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method
                      .GET, fetch_url,
                      new JSONObject(), futureRequest, futureRequest);
              jsonRequest.setTag(REQUEST_TAG);
              mQueue.add(jsonRequest);
              try {
                  return futureRequest.get(10, TimeUnit.SECONDS);
              } catch (InterruptedException | ExecutionException | TimeoutException e) {
                  e.printStackTrace();
              }
              return null;
          }
      }
  }
  </code></pre>
  
  <h1>POST UPDATED:</h1>
  
  <pre><code>@Override
  protected void onHandleIntent(Intent intent) {
      if (intent != null) {
          Bundle data = intent.getExtras();
          if (data != null) {
              String url = data.getString("url");
              startParsingTask(url); //receiving start
          }
      }
  }
  </code></pre>