When executor gets
callExecutor.execute(new MessagesAvailable());
inside MessageAvailable there is a loop:
while ((message = producer.next()) != null) {
<https://github.com/grpc/grpc-java/blob/39c8f4e5846e996389fb5638e5b164b8f1789ef3/core/src/main/java/io/grpc/internal/ClientCallImpl.java#L659>
It looks like the thread may process multiple messages from the producer,
thus sleeping in the thread has no effect if a bunch of messages are
available at the same time.
On Tuesday, February 8, 2022 at 10:15:11 PM UTC-8 mayank kulshreshtha wrote:
> 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
>
>
>
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/812ab813-d23a-46d8-a442-406d09578d49n%40googlegroups.com.