Results 1 to 13 of 13
- 06-05-2014, 06:13 PM #1
Member
- Join Date
- Jun 2014
- Posts
- 7
- Rep Power
- 0
What do I need to close to free memory ?
Hi.
I use poi to read Excel files in a task in Bonita BPM.
When I run this task more than 3 times, it won't work again and I see this error in the log :
org.bonitasoft.engine.connector.exception.SConnect orException: java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
I think it happens because I try to read multiple time in the same file.
I probably need to free memory by closing something in my program but I don't know what.
Here is my code :
Java Code:public static Workbook openWorkbook(String nomFichier, String password) { try { FileInputStream file = new FileInputStream(new File(nomFichier)); BufferedInputStream bufferInput = new BufferedInputStream(file); file.close(); if (nomFichier.endsWith("xls")) { POIFSFileSystem pfs = new POIFSFileSystem(bufferInput); Biff8EncryptionKey.setCurrentUserPassword(password); bufferInput.close(); return new HSSFWorkbook(pfs); } if (nomFichier.endsWith("xlsx")) { POIFSFileSystem pfs = new POIFSFileSystem(bufferInput); EncryptionInfo encInfo = new EncryptionInfo(pfs); Decryptor decryptor = Decryptor.getInstance(encInfo); decryptor.verifyPassword(password); bufferInput.close(); return new XSSFWorkbook(decryptor.getDataStream(pfs)); } if (nomFichier.endsWith("xlsm")) { OPCPackage pkg = OPCPackage.open(new File(nomFichier)); bufferInput.close(); XSSFWorkbook wb = new XSSFWorkbook(pkg); pkg.close(); return wb; } bufferInput.close(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Le fichier doit être au format .xls, .xlsm ou .xlsx !"); return null; } public static ArrayList<String> getListeIdRelease(String nomFichier, String password, String nomOnglet){ Workbook workbook = openWorkbook(nomFichier, password); Sheet sheet = workbook.getSheet(nomOnglet); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); Iterator<Row> rowIterator = sheet.iterator(); TreeSet<String> listeIdRelease = new TreeSet<String>(Collator.getInstance()); while (rowIterator.hasNext()) { Row row = rowIterator.next(); Cell cellRelease = row.getCell(releaseIndex); Cell cellEtat = row.getCell(etatIndex); if (cellRelease != null && cellEtat.getStringCellValue().equals("")) { listeIdRelease.add(getCellValueToString(cellRelease, evaluator)); } } return new ArrayList<String>(listeIdRelease); }
Did you have and idea of what can cause this problem ?
Thanks in advance.
- 06-05-2014, 06:25 PM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: What do I need to close to free memory ?
Excuse me, but how do you reason that you have memory problems from only "org.bonitasoft.engine.connector.exception.SConnec torException: java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError" ?
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 06-05-2014, 06:34 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: What do I need to close to free memory ?
How does that even work for non xlsm files?
Java Code:FileInputStream file = new FileInputStream(new File(nomFichier)); BufferedInputStream bufferInput = new BufferedInputStream(file); file.close();
Also, if you do get an exception in that code, then those streams will not be closed as they are not handled in a finally block.Please do not ask for code as refusal often offends.
** This space for rent **
- 06-06-2014, 10:43 AM #4
Member
- Join Date
- Jun 2014
- Posts
- 7
- Rep Power
- 0
Re: What do I need to close to free memory ?
I don't think this is a memory error because of this line. I don't understand this error.
I think there is a memory problem because the program works fine 3 times and fail after this.
If I close and reopen the software Bonita BPM, it works fine again 3 times and fail after this.
I don't know if the problem is from my code or from Bonita BPM.
Thanks, I will correct this.
I need to add :
Java Code:finally { bufferInput.close(); file.close(); }
If I do that, it says that "file might not have been initialized".
- 06-06-2014, 11:24 AM #5
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: What do I need to close to free memory ?
But that's an incredibly basic Java programming error so I'm sure you know how to fix that. Right?
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 06-06-2014, 12:18 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: What do I need to close to free memory ?
In addition, closing the buffered stream will close the file stream.
No need to close that separately.Please do not ask for code as refusal often offends.
** This space for rent **
- 06-06-2014, 12:39 PM #7
Member
- Join Date
- Jun 2014
- Posts
- 7
- Rep Power
- 0
- 06-06-2014, 12:42 PM #8
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: What do I need to close to free memory ?
If you don't know how to fix that you're trying to hack together complicated code with only a very minimal knowledge of the bare basics of Java programming. In that case there is only one way to go: get a book on basic Java programming and start learning stuff.
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 06-06-2014, 01:10 PM #9
Member
- Join Date
- Jun 2014
- Posts
- 7
- Rep Power
- 0
Re: What do I need to close to free memory ?
I don't think it's so basic if no-one can give me an hint.
I try to create an other simplier example :
Java Code:public class TestExcelCourt { public static void main (String[] args) { System.out.println(getData("D:\\Doc stage\\essai.xlsm", "Feuil1")); } public static String getData(String nomFichier, String nomOnglet) { Workbook workbook = openWorkbook(nomFichier); Sheet sheet = workbook.getSheet(nomOnglet); Row row = sheet.getRow(0); Cell cell = row.getCell(0); return cell.getStringCellValue(); } public static Workbook openWorkbook(String nomFichier) { File file = new File(nomFichier); try { OPCPackage pkg = OPCPackage.open(file); XSSFWorkbook wb = new XSSFWorkbook(pkg); pkg.close(); return wb; } catch (Exception e) { e.printStackTrace(); } return null; } }
And when I import it in Bonita BPM, it works 4 times, and after I have the same problem.
Here is the complete log :
Java Code:2014-06-06 11:52:48 org.bonitasoft.engine.api.impl.ProcessAPIImpl Infos: THREAD_ID=37 | HOSTNAME=W28323 | TENANT_ID=1 | The user <YLombardi> has installed process <Pool4> in version <1.0> with id <5517258604722021641> 2014-06-06 11:52:48 org.bonitasoft.engine.api.impl.transaction.process.EnableProcess Infos: THREAD_ID=37 | HOSTNAME=W28323 | TENANT_ID=1 | The user <YLombardi> has enabled process <Pool4> in version <1.0> with id <5517258604722021641> 2014-06-06 11:52:51 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/bonita].[jsp] Précis: Disabling the response for futher output 2014-06-06 11:52:51 org.bonitasoft.engine.api.impl.ProcessStarter Infos: THREAD_ID=50 | HOSTNAME=W28323 | TENANT_ID=1 | The user <YLombardi> has started the process instance <7> of process <Pool4> in version <1.0> and id <5517258604722021641> 2014-06-06 11:52:51 org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork Avertissement: THREAD_ID=87 | HOSTNAME=W28323 | TENANT_ID=1 | The work [ProcessInstanceContextWork: processInstanceId = 7] failed. The failure will be handled. 2014-06-06 11:52:51 org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork Avertissement: THREAD_ID=87 | HOSTNAME=W28323 | TENANT_ID=1 | org.bonitasoft.engine.core.connector.exception.SConnectorException : "PROCESS_DEFINITION_ID=5517258604722021641 | PROCESS_NAME=Pool4 | PROCESS_VERSION=1.0 | PROCESS_INSTANCE_ID=7 | ROOT_PROCESS_INSTANCE_ID=7 | FLOW_NODE_DEFINITION_ID=-7980742042625586070 | FLOW_NODE_INSTANCE_ID=18 | FLOW_NODE_NAME=Step1 | CONNECTOR_DEFINITION_IMPLEMENTATION_CLASS_NAME=sf | CONNECTOR_INSTANCE_ID=7 | org.bonitasoft.engine.connector.exception.SConnectorException: java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError"
- 06-06-2014, 01:42 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: What do I need to close to free memory ?
If there is no other information available there's not a huge amount we can say.
Does a simple Hello World app work?
Java Code:public static main(String[] args) { System.out.println("Hello World!"); }
To be honest, I would expect more from some bit of code that's supposed to sit in a BPM system...Please do not ask for code as refusal often offends.
** This space for rent **
- 06-06-2014, 02:14 PM #11
Re: What do I need to close to free memory ?
Why are you using OPCPackage? Any good reason not to use the org.apache.poi.ss.usermodel.WorkbookFactory?
Edit: Nevermind. The WorkbookFactory uses OPCPackage as well. Keep moving. Nothing to see here, people.Last edited by SurfMan; 06-06-2014 at 02:21 PM.
"It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013
- 06-06-2014, 02:55 PM #12
Member
- Join Date
- Jun 2014
- Posts
- 7
- Rep Power
- 0
- 06-06-2014, 03:34 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Similar Threads
-
Useful free tool to fix memory leaks
By pedro in forum Java SoftwareReplies: 2Last Post: 07-31-2011, 10:12 PM -
Java not using all free memory.
By abacathoo in forum New To JavaReplies: 10Last Post: 09-13-2010, 12:21 PM -
Will the connection.close() and statement.close() ever be called???
By Stephen Douglas in forum New To JavaReplies: 13Last Post: 04-09-2010, 12:15 PM -
free memory of bufferedimage problem
By mr_empty in forum Java 2DReplies: 2Last Post: 01-17-2010, 07:27 PM -
How Can I get free memory ?
By sathish_2111 in forum NetworkingReplies: 2Last Post: 07-19-2007, 05:29 PM
Bookmarks