complone commented on a change in pull request #10544:
URL: https://github.com/apache/pulsar/pull/10544#discussion_r646169809



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ZeroQueueConsumerImpl.java
##########
@@ -56,6 +62,45 @@ public ZeroQueueConsumerImpl(PulsarClientImpl client, String 
topic, ConsumerConf
         super(client, topic, conf, executorProvider, partitionIndex, 
hasParentConsumer, subscribeFuture,
                 startMessageId, 0 /* startMessageRollbackDurationInSec */, 
schema, interceptors,
                 createTopicIfDoesNotExist);
+        //Actually,i want to achieve to
+        this.messageScheduledFuture = 
Executors.newSingleThreadScheduledExecutor(
+                new 
DefaultThreadFactory(getClass().getSimpleName()+"-receive-message"));
+    }
+
+
+    @Override
+    protected Message<T> internalReceive(int timeout, TimeUnit unit) throws 
PulsarClientException {
+        Message<T> tMessage = null;
+
+        if (Objects.nonNull(conf.getReceiveThreads())){
+            messageScheduledFuture = Executors.newScheduledThreadPool(
+                    conf.getReceiveThreads(),new 
DefaultThreadFactory(getClass().getSimpleName()+"-receive-message")
+            );
+        }
+
+        long time1 = System.nanoTime();
+
+        Supplier<Message<T>> asyncTask = this::doZeroQueue;
+        CompletableFuture<Message<T>> future = new CompletableFuture<>();
+         try {
+             future = FutureUtil.schedule(messageScheduledFuture, asyncTask,
+                     conf.getReceiveInterval(), TimeUnit.SECONDS);
+             //Determine whether the task is over, and then get the result
+             if (future.isDone()) {
+
+                 tMessage = future.get();
+             }
+         }catch (ExecutionException | InterruptedException ignore){
+             long time2 = System.nanoTime();
+             System.out.println("No timeout after " +
+                     (time2-time1)/1000000000.0 + " seconds");
+         }finally {
+             //When the captured futrue throws an exception, the worker thread 
clears the interruption status in time
+             future.cancel(true);

Review comment:
       @linlinnn Because we did not start a thread to complete a task 
execution, I think we should close this futrue in time, and the task call has 
been completed
   
   enmm and the premise implemented here is to allocate a thread pool instance 
in advance




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to