IS it safe to write to multiple sheets from threads?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

IS it safe to write to multiple sheets from threads?

yevsh
Hi,

Is it safe to write to multiple sheets that belong to same workbook, from multiple threads?

*Thread per sheet
*Sheets created under same workbook
      *Sheet creation will be done synchronically.
      *Sheet closing  will be done synchronically.


Reply | Threaded
Open this post in threaded view
|

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

Nick Burch-2
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

David Law-2
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Javen O'Neal-2
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 <[hidden email]> 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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]