I Created the managed channel with a thread pool executor.
ManagedChannel channel = ManagedChannelBuilder.
forAddress("localhost", 6565)
.executor(Executors.
newFixedThreadPool(7))
.usePlaintext()
.build();
this.clientStub = StockQuoteProviderGrpc.
newStub(channel);
the expectation was that the messages which i will receive in observer will be out of order as ClientCallImpl<ReqT, RespT>.class has
callExecutor.execute(new MessagesAvailable());
public class StockResponseStreamObserver implements StreamObserver<StockQuote> {
AtomicInteger atom = new AtomicInteger(0);
@Override
public void onNext(StockQuote stockQuote) {
if(atom.incrementAndGet()%5==0){
System.out.println("T sleeping for 1000 ms " + Thread.currentThread().getName());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(LocalDateTime.now() +" : "+ stockQuote.getPrice()+" description:"+ stockQuote.getDescription()+" T "+Thread.currentThread().getName());
}
but the output is always printed in sequence even with thread.sleep to a random thread.
is this an expected behaviour?
Thanks
Mayank