You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Nate <nm...@charter.net> on 2003/05/20 18:18:38 UTC
Thread issues
Hi all,
I am currently using POI in a web application that is deployed on
Tomcat. Being multithreaded and all, I have a question about threading and
POI. I have a template file that is used by my application to build
spreadsheets on the fly. I am currently opening this as a POIFSFileSystem
object, and passing that to the HSSFWorkbook constructor. If two (or more)
of my users try to create spreadsheets from the same template concurrently,
wouldn't the way I am doing things now present a problem? I had thought
about wrapping them in class that has a method like:
public synchronized POIFSFileSystem getFS() {
return fs;
}
to synchronize the POIFS object. Can anyone see a problem with this? I
understand that it could impact performance, with other threads waiting on
the filesystem object to read.
Thanks for your help (again ;-)
Nathan McMinn
Re: Thread issues
Posted by Nate <nm...@charter.net>.
Gotcha. Nothing in POI is thread-safe. No big deal, it is faster/cleaner
to only synchronize what needs to be threadsafe in the application anyhow.
> "Does this mean that I can't use HSSF in servlets where requests come in
> threads?"
>
> - No. You can. Each thread has a separate instance of HSSF and no two
> instances attempt to modify the same file
This is the exact scenario I am dealing with. I could have a situation
where modification of the same file is going to happen. Thanks for the
insights, this won't be difficult to deal with.
--Nathan
----- Original Message -----
From: "Andrew C. Oliver" <ac...@apache.org>
To: "POI Users List" <po...@jakarta.apache.org>
Sent: Wednesday, May 21, 2003 11:04 AM
Subject: Re: Thread issues
> Avoid saying this loudly because most people don't actually know what it
> means but neither POIFS nor HSSF are thread-safe nor are they intended to
> be.
>
> Now I will answer the next 5-10 impending questions:
>
> "Does this mean that I can't use HSSF in servlets where requests come in
> threads?"
>
> - No. You can. Each thread has a separate instance of HSSF and no two
> instances attempt to modify the same file
>
> "Does this mean that I can't use HSSF near my threads that I launched"
>
> -No. It strictly means that no two threads can access the same instance
of
> HSSFWorkbook or write to the same file at the same time or you'll get
nasty
> errors.
>
> "Why don't you just synchronize every method"
>
> -That would be silly and bad (this would have a performance cost too).
You
> however can wrap whatever you're doing with every method synchronized.
>
> "But I don't like it"
>
> - I'm sorry. When you port a low level binary format to Java I'm sure it
> will be much better despite your lack of understanding of what
thread-safety
> means.."
>
> ;-)
>
> -Andy
>
>
> On 5/21/03 9:14 AM, "Danny Mui" <da...@muibros.com> wrote:
>
> > When testing stuff, I continually new HSSFWorkbook() files with it being
> > open in Excel. I haven't encountered any locking issues there. Though
> > that's not the same as 2 threads accessing the file through POI, it's
> > something of a starting point. I'm going to be running the same
> > environment you mentioned so it would great if you can share your
results!
> >
> > danny
> >
> > Nate wrote:
> >
> >> Hi all,
> >>
> >> I am currently using POI in a web application that is deployed on
> >> Tomcat. Being multithreaded and all, I have a question about threading
and
> >> POI. I have a template file that is used by my application to build
> >> spreadsheets on the fly. I am currently opening this as a
POIFSFileSystem
> >> object, and passing that to the HSSFWorkbook constructor. If two (or
more)
> >> of my users try to create spreadsheets from the same template
concurrently,
> >> wouldn't the way I am doing things now present a problem? I had
thought
> >> about wrapping them in class that has a method like:
> >>
> >> public synchronized POIFSFileSystem getFS() {
> >> return fs;
> >> }
> >>
> >> to synchronize the POIFS object. Can anyone see a problem with this?
I
> >> understand that it could impact performance, with other threads waiting
on
> >> the filesystem object to read.
> >>
> >> Thanks for your help (again ;-)
> >>
> >> Nathan McMinn
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: poi-user-help@jakarta.apache.org
> >>
> >>
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: poi-user-help@jakarta.apache.org
> >
>
> --
> Andrew C. Oliver
> http://www.superlinksoftware.com/poi.jsp
> Custom enhancements and Commercial Implementation for Jakarta POI
>
> http://jakarta.apache.org/poi
> For Java and Excel, Got POI?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
>
>
Re: Thread issues
Posted by "Andrew C. Oliver" <ac...@apache.org>.
Avoid saying this loudly because most people don't actually know what it
means but neither POIFS nor HSSF are thread-safe nor are they intended to
be.
Now I will answer the next 5-10 impending questions:
"Does this mean that I can't use HSSF in servlets where requests come in
threads?"
- No. You can. Each thread has a separate instance of HSSF and no two
instances attempt to modify the same file
"Does this mean that I can't use HSSF near my threads that I launched"
-No. It strictly means that no two threads can access the same instance of
HSSFWorkbook or write to the same file at the same time or you'll get nasty
errors.
"Why don't you just synchronize every method"
-That would be silly and bad (this would have a performance cost too). You
however can wrap whatever you're doing with every method synchronized.
"But I don't like it"
- I'm sorry. When you port a low level binary format to Java I'm sure it
will be much better despite your lack of understanding of what thread-safety
means.."
;-)
-Andy
On 5/21/03 9:14 AM, "Danny Mui" <da...@muibros.com> wrote:
> When testing stuff, I continually new HSSFWorkbook() files with it being
> open in Excel. I haven't encountered any locking issues there. Though
> that's not the same as 2 threads accessing the file through POI, it's
> something of a starting point. I'm going to be running the same
> environment you mentioned so it would great if you can share your results!
>
> danny
>
> Nate wrote:
>
>> Hi all,
>>
>> I am currently using POI in a web application that is deployed on
>> Tomcat. Being multithreaded and all, I have a question about threading and
>> POI. I have a template file that is used by my application to build
>> spreadsheets on the fly. I am currently opening this as a POIFSFileSystem
>> object, and passing that to the HSSFWorkbook constructor. If two (or more)
>> of my users try to create spreadsheets from the same template concurrently,
>> wouldn't the way I am doing things now present a problem? I had thought
>> about wrapping them in class that has a method like:
>>
>> public synchronized POIFSFileSystem getFS() {
>> return fs;
>> }
>>
>> to synchronize the POIFS object. Can anyone see a problem with this? I
>> understand that it could impact performance, with other threads waiting on
>> the filesystem object to read.
>>
>> Thanks for your help (again ;-)
>>
>> Nathan McMinn
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: poi-user-help@jakarta.apache.org
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
>
--
Andrew C. Oliver
http://www.superlinksoftware.com/poi.jsp
Custom enhancements and Commercial Implementation for Jakarta POI
http://jakarta.apache.org/poi
For Java and Excel, Got POI?
Re: Thread issues
Posted by Danny Mui <da...@muibros.com>.
When testing stuff, I continually new HSSFWorkbook() files with it being
open in Excel. I haven't encountered any locking issues there. Though
that's not the same as 2 threads accessing the file through POI, it's
something of a starting point. I'm going to be running the same
environment you mentioned so it would great if you can share your results!
danny
Nate wrote:
>Hi all,
>
> I am currently using POI in a web application that is deployed on
>Tomcat. Being multithreaded and all, I have a question about threading and
>POI. I have a template file that is used by my application to build
>spreadsheets on the fly. I am currently opening this as a POIFSFileSystem
>object, and passing that to the HSSFWorkbook constructor. If two (or more)
>of my users try to create spreadsheets from the same template concurrently,
>wouldn't the way I am doing things now present a problem? I had thought
>about wrapping them in class that has a method like:
>
>public synchronized POIFSFileSystem getFS() {
> return fs;
>}
>
>to synchronize the POIFS object. Can anyone see a problem with this? I
>understand that it could impact performance, with other threads waiting on
>the filesystem object to read.
>
>Thanks for your help (again ;-)
>
>Nathan McMinn
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: poi-user-help@jakarta.apache.org
>
>
>