adding the sleep for every 5th thread is to introduce a delay in every 5th 
message to make it loose the order but that did not happen.
interestingly i am getting messages one by one. at server side i could see 
all messages are printed immediately so its not like client is requesting 
one by one.

On Thursday, 10 February 2022 at 05:26:16 UTC+11 [email protected] wrote:

> 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/22a3473e-9ad5-42fc-ad84-473effc68been%40googlegroups.com.

Reply via email to