咱們要保持項目中惟一一個Volley的RequestQueue,使用單例模式來實現
public class NetRequest {spa
private static RequestQueue mQueue = null;
private static Lock lock = new ReentrantLock();
private static final String NETREQUEST = "netrequest";
public static RequestQueue getInstance(Context context) {
if (mQueue == null) {
lock.lock();
if (mQueue == null) {
mQueue = Volley.newRequestQueue(context.getApplicationContext());
}
lock.unlock();
}
return mQueue;
}
}get