Thank you for writing, Nick.

On Thu, 2022-05-19 at 18:09 +0100, Nick Burch wrote:
> On Mon, 16 May 2022, Andreas Reichel wrote:
> > Of course I am fully aware that POI is not thread safety on
> > workbook
> > level and threads can only be used as long as every sheet is
> > processed
> > within its own thread (without altering styles).
> 
> We only ensure that you are safe if each workbook is created in its
> own 
> thread, we generally advise against having multiple threads working
> on the 
> same workbook as it often goes wrong. It sounds like you've pushed
> things 
> well beyond our normally recommended limits already...

Oh! I thought we would be thread safe down to sheet level?
Because I am able to create MANY and LARGE sheets in parallel just fine
-- as long as actions within each thread refer to only the sheet.

Styles and sheets are to be created before the threads spawn.
Workbook formula evaluation is done after the threads joined.

The only confusion was about:

Sheet sheet = workbook.createSheet(p[4]);

Because this returns the sheet (and so would have been expected within
the thread), but in fact its Workbook related and must happen before
the threads spawn.

> Won't that slow down the 99.9% case, where people are just using a
> single 
> thread for the whole workbook? 

Locking a Semaphore does not take (much) time.
The 99.9% case creates some simple sheets and will not notice 100 ms
for the locking.

The remaining 0.01% who are pushing it and create 500 MB Excel files
will save multiple minutes from parallelism.
(My report builder reduce time from 20 mins to less than 2 minutes just
by writing to the sheets in parallel. Its a huge benefit for us!)

> And doesn't it risk people trying to do 
> things that aren't generally thread-safe because "that bit seemed
> fine" 
> and getting stuck later?

Very correct and agreed. I am still curious what the ACTUAL limitations
are: Are we just overly defensive/careful declaring it "threadsafe as
per Workbook" only?
Or are there real show stoppers to work on different sheets in parallel
(each sheet in its own thread without cross references of course).

I feel like its the second one, and then we could synchronize those
methods .

Cheers
Andreas

Reply via email to