Thanks Dominik - seems like a valid solution. Ideally, there would be separate 
ThreadLocalUtil-like classes for poi-ooxml and poi-scratchpad (XSSF vs HSSF) - 
and probably poi main jar too.

I was thinking myself more along the lines of supporting a flag to turn off the 
use of ThreadLocals (not the default mode, an opt in). This could still be 
added as a separate util method. I think this latter mode will prove use once 
Virtual Threads become more common.






On Friday 10 March 2023 at 12:51:40 GMT+1, Dominik Stadler 
<dominik.stad...@gmx.at> wrote: 





Hi,

Some of them likely have had a valid use-case and would at least cause
performance issues if removed.

The issues from Tomcat or other WebServers usually come because they check
if memory is lingering at the point when the thread is "given back" to a
global pool.

XmlBeans also uses ThreadLocals and there were similar reports some time
ago. There we provide
https://github.com/apache/xmlbeans/blob/trunk/src/main/java/org/apache/xmlbeans/ThreadLocalUtil.java
which allows to clean out all ThreadLocals in the current thread and can be
used in a Web-Application to release stuff at the end if necessary.

I would propose to provide a similar util for POI, I even have an initial
version of it, but never managed to finish it. Unless you object I can tidy
it up and add it as solution for anyone having issues with threadlocals.

Dominik.

On Wed, Mar 8, 2023 at 10:09 PM PJ Fanning <fannin...@yahoo.com.invalid>
wrote:

> Hi everyone,
>
> We have a lot of open issues about ThreadLocals.
> https://bz.apache.org/bugzilla/show_bug.cgi?id=66521 was opened today.
>
> With Virtual Threads (aka Project Loom), ThreadLocals seem like a bad
> solution.
>
> I've looked at the ThreadLocals in POI a few times and have always
> struggled to see what they really achieve.
>
> Would anyone object if we just simply remove them all?
>
> Interacting with individual HSSFWorkbook, XSSFWorkbook and their
> equivalents using multiple threads seems to be something that we don't test
> much and we could simply say it's a bad idea. Sure, being able to produce
> multiple separate docs with separate threads is definitely something we
> want.
>
> Does anyone have any thoughts?
>
> Regards,
> PJ
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
> For additional commands, e-mail: dev-h...@poi.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to