parallel-consumer icon indicating copy to clipboard operation
parallel-consumer copied to clipboard

Add support for virtual threads

Open bdeneuter opened this issue 1 year ago • 5 comments

Hi,

This is a feature request. Virtual threads were added to the JDK in JDK 21. It still had an issue with pinning which has been fixed with https://openjdk.org/jeps/491 in JDK 24. JDK 25 became the first LTS which has support for virtual threads without the pinning issue. It would be nice to have support for virtual threads for processing when running on JDK 25. I created a fork with a first implementation but I didn't find the time to get the Maven build working correctly. I tried to keep the original build and have only the module parallel-consumer-virtual-threads build on JDK 25 but didn't succeed yet. You find a rough version from the code here: https://github.com/bdeneuter/parallel-consumer/blob/master/parallel-consumer-virtual-threads/src/main/java/io/confluent/parallelconsumer/virtual_thread/VirtualThreadProcessor.java

I based the implementation on the reactor version.

bdeneuter avatar Oct 27 '25 15:10 bdeneuter

I achieved virtual threads with io.confluent.parallelconsumer:parallel-consumer-core:0.5.3.3 by doing the following:

public class Main {

  static {
    new VirtualThreadJavaxNamingConfigurer().configure();
  }

   public static void main(String[] args) {
     ..
  }

}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

import javax.naming.Context;

import com.mageddo.naming.Contexts;
import com.mageddo.naming.SimpleContextFactory;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class VirtualThreadJavaxNamingConfigurer {

  /**
   * Path to Managed executor service for Java EE
   */
  private static final String MANAGED_EXECUTOR_SERVICE = "java:comp/DefaultManagedExecutorService";

  /**
   * Path to Managed thread factory for Java EE
   */
  private static final String MANAGED_THREAD_FACTORY = "java:comp/DefaultManagedThreadFactory";

  private final ExecutorService executorService;
  private final ThreadFactory threadFactory;

  public VirtualThreadJavaxNamingConfigurer() {
    this.executorService = Executors.newVirtualThreadPerTaskExecutor();
    this.threadFactory = Thread.ofVirtual()
        .name("virt-", 0)
        .factory();
  }

  public void configure() {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, SimpleContextFactory.class.getName());
    Contexts.rebind(MANAGED_EXECUTOR_SERVICE, this.executorService);
    Contexts.rebind(MANAGED_THREAD_FACTORY, this.threadFactory);
    log.debug("status=configuredVirtualThreadForJavaEE");
  }

}

SimpleContextFactory.java SimpleContext.java Contexts.java

mageddo avatar Jan 27 '26 23:01 mageddo

Tracked in the maintained fork as astubbs/parallel-consumer#190, which carries a summary of this issue and its current status there.

The Confluent-hosted version of this project is no longer maintained - its README says so. Parallel Consumer itself continues in my fork: https://github.com/astubbs/parallel-consumer

Nothing in this repository is closed or changed by this comment.

astubbs avatar Aug 05 '26 00:08 astubbs

I found this through the offset-reset/frequent-rebalancing problem.

ReplayGuard wouldn't change Parallel Consumer's internal rebalance state; we're working on external safeguards around the recovery operation itself — resolve/preview target offsets, validate scope, execute under controls and retain an audit trail.

Is the main pain here reset correctness during rebalances, repeated operator intervention, or reconciling Parallel Consumer state afterward?

https://replayguard.in/

ravithejatech714-create avatar Aug 29 '26 14:08 ravithejatech714-create

There is no pain anymore :) This is implemented in https://github.com/astubbs/parallel-consumer/pull/360 and is merging soon.

astubbs avatar Aug 31 '26 08:08 astubbs

Thanks Antony — good to know this is already implemented and on its way in.

I had connected this issue too strongly to the offset-reset/recovery angle, so thanks for the correction. Glad to hear there isn't an outstanding operational pain here anymore.

ravithejatech714-create avatar Sep 01 '26 03:09 ravithejatech714-create