Code example for ArrayDeque

Methods: offer, poll

0
		final ArrayDeque<Runnable> mTasks = new ArrayDeque<Runnable>();
		Runnable mActive;
 
		public synchronized void execute(final Runnable r)
		{ 
			mTasks.offer(new Runnable()
			{ 
				public void run() 
				{ 
					try 
					{ 
						r.run();
					} finally 
					{ 
						scheduleNext(); 
					} 
				} 
			}); 
			if (mActive == null)
			{ 
				scheduleNext(); 
			} 
		} 
 
		protected synchronized void scheduleNext() 
		{ 
			if ((mActive = mTasks.poll()) != null)
			{ 
				THREAD_POOL_EXECUTOR.execute(mActive);
			} 
		} 
	}