Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

java.lang.OutOfMemoryError in Eclipse

Options
  • 19-05-2009 2:42pm
    #1
    Registered Users Posts: 7,681 ✭✭✭


    I have the following method in a java application which keeps throwing the above error if I request a file which size is over 4 Megs on the line marked in bold.

    Any ideas what could be causing the problem or ideas how to capture it?

    Could it be a machine problem rather than a code problem?

    Thank you for looking
    
    public void run() 
    {
    	String docId = "";
    	String docErr = " (DOCID:Unavailable)";
    	ParamList paramList = new ParamList();
    	Document responseDocument = null;
    	Base64Coder bc = null;
    	String returnXML;
    
    	try 
    	{
    		MQQueue iOutputQueue = manager.accessQueue(iOutputQueueName,
    		openOutputOptions, null, null, null);
    		// Get a String from the message
    		String requestXML = message.readString(message.getDataLength());
    
    		// Convert the String into an XML document
    		DOMParser parser = new DOMParser();
    		parser.parse(new InputSource(new StringReader(requestXML)));
    		responseDocument = parser.getDocument();
    
    		// Get an MQ paramList from the XML
    
    		paramList = MessageHandler.handle(responseDocument,
    			(DocumentTraversal) responseDocument);
    
    		// Get the Document ID from the paramList
    		docId = paramList.getStringParam(FINAL_DocId);
    
    		int xPos = requestXML.indexOf("<DOCID>", 0) + 7;
    		docId = requestXML.substring(xPos);
    		xPos = docId.indexOf("</DOCID>", 0);
    		docId = docId.substring(0, xPos);
    
    		docErr = " (DOCID:" + docId + ")";
    
    		if (requestXML == null) 
    		{
    			// The XML is blank so do nothing
    			System.out.println("Message was null");
    		} else 
    		{
    			// The XML has something in it so let's try and get the
    			// document
    			// from FileNet
    
    			byte[] returnData = null;
    			// Send the byte data back in an MQ message
    			MQMessage responseMessage = null;
    			MQPutMessageOptions pmo = new MQPutMessageOptions();
    			responseMessage = new MQMessage();
    			responseMessage.correlationId = message.messageId;
    			String replyTest = message.replyToQueueName;
    
    			// Get the Document contents for the given Doc ID
    			// This is returned as bytes
    
    			returnData = is.getDocContent(docId);
    			// Check the file size is not bigger than the limit
    			if (returnData.length <= MAX_FILE_SIZE) 
    			{
    				bc = new Base64Coder();
    				String es = bc.encode(returnData);
    				// Create the outputmessage
    				returnXML = createOuputMessage(replyTest, docId, es, is
    				.getFileName(), is.getMimeType());
    				//responseMessage.write(returnData);
    				responseMessage.writeString(returnXML);
    				iOutputQueue.put(responseMessage, pmo);
    			} else 
    			{
    				createMQErrorMessage(docId, "ER_MAX_SIZE",
    				"File size is bigger than " + MAX_FILE_SIZE + "bytes");
    			}					
    
    			// Testing... save a copy of the pdf returned from FileNet
    			// to
    			// disk
    
    			/*
    			 * File file = null; file = new File("C:/isra_files_test/" +
    			 * docId + "_" + threadName + "_" + message.messageId +
    			 * ".pdf"); // // Now write the data to the file.
    			 * 
    			 * try 
    			{ 
    				// Create an output stream to the file.
    				 * FileOutputStream file_output = new FileOutputStream(
    				 * file); // Wrap the FileOutputStream with a
    				 * DataOutputStream DataOutputStream data_out = new
    				 * DataOutputStream( file_output); // Write the data to the
    				 * file data_out.write(returnData); byte[] esX =
    				 * Base64Coder.decode(es); data_out.write(esX); // Close
    				 * file when finished with it.. file_output.close(); 
    			} 
    			catch
    			 * (IOException e) 
    			{ 
    				System.out.println("IO exception = " + * e); 
    			}
    			 */
    		}
    	} catch (MQException me) 
    	{
    		ExceptionHandler.handleException(me,
    		"Error sending response message" + docErr);
    		createMQErrorMessage(docId, "ER_MQ", me.getMessage());
    	} catch (ResourceException re) 
    	{
    		ExceptionHandler.handleException(re,
    		"Error connecting to DMS message" + docErr);
    		createMQErrorMessage(docId, re.getErrorCode(), re
    		.getLocalizedMessage());
    	} catch (SAXException saxe) {
    		ExceptionHandler.handleException(saxe, "Error in sax parser"
    		+ docErr);
    		createMQErrorMessage(docId, "ER_SAX", saxe.getMessage());
    	} catch (IOException ioe) {
    		ExceptionHandler.handleException(ioe,
    		"Error reading message contents" + docErr);
    		createMQErrorMessage(docId, "ER_IO", ioe.getMessage());
    	} catch (Exception e) {
    		ExceptionHandler.handleException(e, "Error (not recognized)"
    		+ docErr);
    		createMQErrorMessage(docId, "ER_E", e.getMessage());
    	} finally {
    		// close the MQQueueManager connection
    		try 
    		{
    			manager.close();
    		} catch (MQException me) 
    		{
    			ExceptionHandler.handleException(me,
    			"Error closing MQQueueManager" + docErr);
    		}
    	[SIZE="4"][B][COLOR="Black"]}[/COLOR][/B][/SIZE]
    }
    
    


Comments

  • Registered Users Posts: 1,998 ✭✭✭lynchie


    Increase your heap size -Xmx512m should do the trick


  • Registered Users Posts: 7,681 ✭✭✭Trampas


    Change the file to

    -vmargs
    -Xms128m
    -Xmx512m
    -XX:MaxPermSize=128m

    and still getting the problem


  • Registered Users Posts: 1,998 ✭✭✭lynchie


    Let me guess. you changed the eclipse.ini? That only governs the IDE. Running apps within the IDE launches its own jvm. Add the above parameter to the jvm args section under the run configuration for your app.


Advertisement