You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Warren Tang <wa...@gmail.com> on 2012/03/05 01:27:31 UTC
HSSF eventusermodel & field read/write problem.
Hi, everybody
I came across performance issue when reading large Excel97 files with
usermodel. When the file size is over 15MB, the HSSFWorkbook's constructor
never returns or returns with an OutOfMemoryError (GC overhead limit
exceeded).
So I've been trying to use eventusermodel to reduce the memory footprint,
but I have problem to pertain the value of the modified fields. Below is
the code. I need the modified value of an instance field (modifyMe); but
the value is always 0 rather than 100 which is what I want.
----------------------------- HssfEventApiTest.java
----------------------------------------
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
import org.apache.poi.hssf.eventusermodel.HSSFListener;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.junit.Test;
import com.tangcs.zhc.server.ServerTestBase;
public class HssfEventApiTest extends ServerTestBase
implements HSSFListener
{
int modifyMe; // The instance field to be modified by the listener
public void processRecord(Record record)
{
switch (record.getSid())
{
case EOFRecord.sid:
modifyMe = 100; //Modified here.
System.out.println("End of file.");
break;
}
}
@Test public void testEventApi() throws IOException
{
InputStream fin = getResourceAsStream("xls/exam-results-min.xls");
POIFSFileSystem poifs = new POIFSFileSystem(fin);
InputStream din = poifs.createDocumentInputStream("Workbook");
HSSFRequest req = new HSSFRequest();
req.addListenerForAllRecords(new HssfEventApiTest());
HSSFEventFactory factory = new HSSFEventFactory();
factory.processEvents(req, din);
fin.close();
din.close();
System.out.println("modifyMe = " + modifyMe);
assertEquals(100, modifyMe); //Fails here with actual == 0;
// The stdout is:
// End of file.
// End of file.
// modifyMe = 0
}
}
--
Regards,
Warren Tang <http://blog.tangcs.com>
Re: HSSF eventusermodel & field read/write problem.
Posted by Warren Tang <wa...@gmail.com>.
Is it a thread synchronization problem? I tried to guard every access
to the "modifyMe" field with "sychronized" keyword, however it did not
work.
Regards,
Warren Tang <http://blog.tangcs.com>
On Thursday, March 08, 2012 8:57:29 PM, Warren Tang wrote:
> Hi, Nick
> Thanks for the reply. I've read everything I could find, but none
> covers my case. The problem is how to get the return value (i.e. the
> field modified by the event API), as my code suggests.
>
> Regards,
> Warren Tang <http://blog.tangcs.com>
>
>
> On Thursday, March 08, 2012 6:21:12 PM, Nick Burch wrote:
>> On Thu, 8 Mar 2012, Warren Tang wrote:
>>> Any idea? Is event api ready to use? I see little doc or discussions
>>> about it.
>>
>> Should work just fine. There is some documentation and examples for it
>> on the website, and there are several example uses of it provided (in
>> both the examples package, and as text extractors). I'd suggest you
>> review those
>>
>> 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: HSSF eventusermodel & field read/write problem.
Posted by Warren Tang <wa...@gmail.com>.
Hi, Nick
Thanks for the reply. I've read everything I could find, but none
covers my case. The problem is how to get the return value (i.e. the
field modified by the event API), as my code suggests.
Regards,
Warren Tang <http://blog.tangcs.com>
On Thursday, March 08, 2012 6:21:12 PM, Nick Burch wrote:
> On Thu, 8 Mar 2012, Warren Tang wrote:
>> Any idea? Is event api ready to use? I see little doc or discussions
>> about it.
>
> Should work just fine. There is some documentation and examples for it
> on the website, and there are several example uses of it provided (in
> both the examples package, and as text extractors). I'd suggest you
> review those
>
> 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: HSSF eventusermodel & field read/write problem.
Posted by Nick Burch <ni...@alfresco.com>.
On Thu, 8 Mar 2012, Warren Tang wrote:
> Any idea? Is event api ready to use? I see little doc or discussions
> about it.
Should work just fine. There is some documentation and examples for it on
the website, and there are several example uses of it provided (in both
the examples package, and as text extractors). I'd suggest you review
those
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: HSSF eventusermodel & field read/write problem.
Posted by Warren Tang <wa...@gmail.com>.
Any idea? Is event api ready to use? I see little doc or discussions about
it.
On Mon, Mar 5, 2012 at 8:27 AM, Warren Tang <wa...@gmail.com> wrote:
> Hi, everybody
>
> I came across performance issue when reading large Excel97 files with
> usermodel. When the file size is over 15MB, the HSSFWorkbook's constructor
> never returns or returns with an OutOfMemoryError (GC overhead limit
> exceeded).
>
> So I've been trying to use eventusermodel to reduce the memory footprint,
> but I have problem to pertain the value of the modified fields. Below is
> the code. I need the modified value of an instance field (modifyMe); but
> the value is always 0 rather than 100 which is what I want.
>
>
> ----------------------------- HssfEventApiTest.java
> ----------------------------------------
> import static org.junit.Assert.*;
> import java.io.IOException;
> import java.io.InputStream;
> import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
> import org.apache.poi.hssf.eventusermodel.HSSFListener;
> import org.apache.poi.hssf.eventusermodel.HSSFRequest;
> import org.apache.poi.hssf.record.EOFRecord;
> import org.apache.poi.hssf.record.Record;
> import org.apache.poi.poifs.filesystem.POIFSFileSystem;
> import org.junit.Test;
> import com.tangcs.zhc.server.ServerTestBase;
>
> public class HssfEventApiTest extends ServerTestBase
> implements HSSFListener
> {
> int modifyMe; // The instance field to be modified by the listener
>
> public void processRecord(Record record)
> {
> switch (record.getSid())
> {
> case EOFRecord.sid:
> modifyMe = 100; //Modified here.
> System.out.println("End of file.");
> break;
> }
> }
>
> @Test public void testEventApi() throws IOException
> {
> InputStream fin = getResourceAsStream("xls/exam-results-min.xls");
> POIFSFileSystem poifs = new POIFSFileSystem(fin);
> InputStream din = poifs.createDocumentInputStream("Workbook");
> HSSFRequest req = new HSSFRequest();
> req.addListenerForAllRecords(new HssfEventApiTest());
> HSSFEventFactory factory = new HSSFEventFactory();
> factory.processEvents(req, din);
> fin.close();
> din.close();
>
> System.out.println("modifyMe = " + modifyMe);
> assertEquals(100, modifyMe); //Fails here with actual == 0;
> // The stdout is:
> // End of file.
> // End of file.
> // modifyMe = 0
> }
>
> }
>
> --
> Regards,
> Warren Tang <http://blog.tangcs.com>
>
--
Regards,
Warren Tang <http://blog.tangcs.com>