You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Brant Schlatzer <bs...@yahoo.com> on 2003/02/02 07:12:46 UTC

file locking?

Hi-

I'm fairly new to POI, and in order to learn about it (in particular HSSF), I've
been hacking on a simple web app to collect fields from a registration form and
append them to a "registrations.xls" file. I've had no problem getting the basic
functionality together, but it occurred to me that since in order to add new
"registrations" I'm reading the file into memory and using:

	HSSFRow row = sheet.createRow((short)(sheet.getLastRowNum() + 1));

...to append a row, it's possible that another instance of my class might well
add a row before I call wb.write(), resulting in one instance stomping on the
row created by the other. Could anyone suggest an appropriate means of locking
the file to be written, or perhaps an alternative approach? Is there a simpler
means to just "append" any new rows at wb.write() time as opposed to assigning
them explicit numbers?

Thanks in advance for your help!

-Brant


Re: file locking?

Posted by Avik Sengupta <av...@apache.org>.
You'll have to synchronize on the workbook instance in you code. There
is no magic solution here i suppose. 


On Sun, 2003-02-02 at 11:42, Brant Schlatzer wrote:
> Hi-
> 
> I'm fairly new to POI, and in order to learn about it (in particular HSSF), I've
> been hacking on a simple web app to collect fields from a registration form and
> append them to a "registrations.xls" file. I've had no problem getting the basic
> functionality together, but it occurred to me that since in order to add new
> "registrations" I'm reading the file into memory and using:
> 
> 	HSSFRow row = sheet.createRow((short)(sheet.getLastRowNum() + 1));
> 
> ...to append a row, it's possible that another instance of my class might well
> add a row before I call wb.write(), resulting in one instance stomping on the
> row created by the other. Could anyone suggest an appropriate means of locking
> the file to be written, or perhaps an alternative approach? Is there a simpler
> means to just "append" any new rows at wb.write() time as opposed to assigning
> them explicit numbers?
> 
> Thanks in advance for your help!
> 
> -Brant
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
>