Java lambdas LinkedBlockingQueue unexpected behaviour
<p>I am trying to add elements in t linkedBlockingQueue from a thread, created using lambda, When I poll the queue using the take method, I can see that the last values entered from the thread overrides the previous values.</p>

<p>Following is the code :-</p>

<pre><code>public List&lt;EntryBarricade&gt; entryBarricades() {
    List&lt;EntryBarricade&gt; entryBarricades = new ArrayList&lt;&gt;();
    EntryBarricade entryBarricade;
    Runnable runnable;

    for (int i =0;i&lt;=1;i++) {
        EntryRequest entryRequest =  new EntryRequest("Barricade-"+i);
        runnable = new Runnable() {
            @Override
            public void run() {
                ExecutorService entryGate1 = Executors.newSingleThreadExecutor();
                for (int j =0;j&lt;=1;j++) {
                    entryGate1.submit(() -&gt; {
                        entryRequest.setVehicleId(Thread.currentThread().getName()
                                + " " + new Double(Math.random()));
                        entryRequestQueuingService.Queue(entryRequest);
                    });
                }
            }
        };
        entryBarricade = new EntryBarricade("Barricade-"+i, runnable);
        entryBarricades.add(entryBarricade);
    }
    return entryBarricades;
}
</code></pre>

<p>After polling the queue, I get the following:-</p>

<p>Request{barricadeId='Barricade-0', vehicleId='pool-2-thread-1 0.9091480024731418'}
Request{barricadeId='Barricade-0', vehicleId='pool-2-thread-1 0.05687657229049259'}
Request{barricadeId='Barricade-1', vehicleId='pool-3-thread-1 0.7978996055410615'}
Request{barricadeId='Barricade-1', vehicleId='pool-3-thread-1 0.2734508504023724'}</p>

<p>Request{barricadeId='Barricade-0', vehicleId='pool-2-thread-1 0.05687657229049259'}
Request{barricadeId='Barricade-0', vehicleId='pool-2-thread-1 0.05687657229049259'}
Request{barricadeId='Barricade-1', vehicleId='pool-3-thread-1 0.2734508504023724'}
Request{barricadeId='Barricade-1', vehicleId='pool-3-thread-1 0.2734508504023724'}</p>

<p>I am not sure what is happening.
Can some one please explain this behaviour ??</p>

<p>Thanks,</p>

<p>Amar</p>