usb4java-javax icon indicating copy to clipboard operation
usb4java-javax copied to clipboard

Threading

Open riewert opened this issue 4 years ago • 0 comments

In practice AbstractIrpQueue spawns a new thread whenever an Irp is added. For asyncSubmit this makes a little sense, though reusing the a single thread per pipe would be a lot better. For the syncSubmit usecase it makes no sense to do this. It is very resource intense. By making the following modification I was able to increase performance by a factor of 10x.

    public final void add(final T irp)
    {
        this.irps.add(irp);

        // Start the queue processor if not already running.
//        if (this.processor == null)
//        {
//            this.processor = new Thread(new Runnable()
//            {
//                @Override
//                public void run()
//                {
                    process();
//                }
//            });
//            this.processor.setDaemon(true);
//            this.processor.setName("usb4java IRP Queue Processor");
//            this.processor.start();
//        }
    }

When using syncSubmit an Irp is added to the queue, and the processor thread is started, when the processor finishes executing the Irp the thread is destroyed again. Meanwhile the syncSubmit thread is waiting. A cleaner solution might be to wait() the processor thread until a new irp is added. That would work for asyncSubmit too. But is not relevant for my usecase.

riewert avatar Jan 29 '21 09:01 riewert