You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by David Law <da...@apconsult.de> on 2017/05/14 18:17:53 UTC

Re: Is it safe to write to multiple sheets from threads?

Nick,

no idea whether the motivation is performance or just plain convenience,
but is it conceivable one could write each Sheet with a dedicated
Thread to separate WorkBooks & then merge the finished Sheets
into a single WorkBook in a final step?

Would there be any advantage in that?

All the best,
DaveLaw

On 14/05/2017 17:15, Nick Burch wrote:
> On Sat, 13 May 2017, yevsh wrote:
>> Is it safe to write to multiple sheets that belong to same workbook, 
>> from multiple threads?
>
> No
>
> It is safe for multiple threads to write to their own workbooks. 
> However, all operations on a single workbook must be done from the 
> same thread
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Is it safe to write to multiple sheets from threads?

Posted by Javen O'Neal <on...@apache.org>.
Copying a sheet from another workbook is non-trivial.
You would have to check that the sheet names in one workbook do not
conflict with the sheet names in another book (case insensitive
compare, probably).
Any custom cell styles, data formats, images, and other resources
would have to be copied over and appended to the first sheet.
Any formulas would have to be adjusted
Any data objects that store sheet index instead of sheet name would
have to be adjusted.

It can be done, and if you are generating both workbooks from scratch
(and therefore know that you won't have any formulas, cell styles,
data formats, or embedded objects to copy over, then this might not be
too difficult.

That said, how much RAM are you running? POI is pretty memory hungry,
so running parallel instances means you'll have multiple workbooks
open at the same time. Just something to consider. For the files I
work with, I need 1GB of RAM per 4MB of xlsx file to read one
workbook, work on it, save it to another file, and close it.

On Sun, May 14, 2017 at 11:17 AM, David Law <da...@apconsult.de> wrote:
> Nick,
>
> no idea whether the motivation is performance or just plain convenience,
> but is it conceivable one could write each Sheet with a dedicated
> Thread to separate WorkBooks & then merge the finished Sheets
> into a single WorkBook in a final step?
>
> Would there be any advantage in that?
>
> All the best,
> DaveLaw
>
> On 14/05/2017 17:15, Nick Burch wrote:
>>
>> On Sat, 13 May 2017, yevsh wrote:
>>>
>>> Is it safe to write to multiple sheets that belong to same workbook, from
>>> multiple threads?
>>
>>
>> No
>>
>> It is safe for multiple threads to write to their own workbooks. However,
>> all operations on a single workbook must be done from the same thread
>>
>> Nick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org