All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mchange.v2.c3p0.loom.UninstrumentedVirtualThreadPerTaskTaskRunnerFactory~ Maven / Gradle / Ivy

Go to download

A c3p0 TaskRunnerFactory that outsources asynchronous work to Java 21 virtual threads

The newest version!
package com.mchange.v2.c3p0.loom;

import com.mchange.v2.async.*;
import com.mchange.v2.c3p0.*;
import com.mchange.v2.log.*;
import java.util.Timer;

public final class VirtualThreadPerTaskDirectTaskRunnerFactory implements TaskRunnerFactory
{
    //MT: thread-safe
    final static MLogger logger = MLog.getLogger( ThreadPerTaskRunnerFactory.class );

    public ThreadPoolReportingAsynchronousRunner createTaskRunner(
        int num_threads_if_supported,
        int max_administrative_task_time_if_supported, // in seconds!
        String contextClassLoaderSourceIfSupported,
        boolean privilege_spawned_threads_if_supported,
        String threadLabelIfSupported,
        ConnectionPoolDataSource cpds,
        Timer timer
    )
    {
    }

    private static class Runner implements ThreadPoolReportingAsynchronousRunner
    {
        private Timer timer;
        int     matt_ms;

        Runner( Timer timer, int matt_ms )
        {
            this.timer = timer;
            this.matt_ms = matt_ms;
        }

        public void postRunnable(Runnable r)
        {
            final Thread t = tf.newThread(r);
            t.start();

            if (matt_ms > 0)
                {
                    TimerTask tt = new TimerTask()
                        {
                            public void run() { t.interrupt(); }
                        };
                    timer.schedule( tt, matt_ms );
                }
        }

        public void close( boolean skip_remaining_tasks ) { if (skip_remaining_tasks) ourGroup.interrupt(); }
        public void close() { close( true ); }

        public int getThreadCount() { return -1; }
        public int getActiveCount() { return -1; }
        public int getIdleCount() { return 0; }
        public int getPendingTaskCount() { return 0; }

        public String getStatus()
        { return "VirtualThreadPerTaskDirectTaskRunnerFactory.Runner (No further information)"; }

        public String getStackTraces()
        { return "[StackTraces not available]"; }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy