问题描述
Exception in thread "main" java.lang.OutOfMemoryError:
Java heap space
解决方案[转]
一直都知道可以设置jvm heap大小,一直用eclipse写/调试java程序。一直用命令行or
console加参数跑程序。现象:在eclipse的配置文件eclipse.ini中设置-vmargs -Xms500m
-Xmx1024m
,在eclipse中直接run
或者debug某些耗内存的程序时依然出现java.lang.OutOfMemoryError: Java Heap
Space错误,即通常认为的内存不足,java虚拟机内存不够用。而在命令行加这些参数则有效果,不会出错。这说明一个问题,
这些参数根本没有起作用
。今天需要在eclipse里调试程序,还没到需要调试的地方就heap
error了,在网上搜了很多地方,得到了最终的答案:
选中被运行的类,点击菜单‘
run->run...
’,
选择(x)=Argument标签页下的vm arguments
框
里
输入 -Xmx800m
, 保存运行。
原来还需要对每个project单独设置
,汗...
有三种可能导致OutOfMemoryError。首先是,此JVM有真实的内存泄漏,导致此JVM堆在内部实现时产生了一个Bug。这极不可靠。所有
JVM都经过充分的测试,并且,如果有人发现这种bug,它将绝对是最高的优先级 ......
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Usage: You can get a instance of Document from a string of xml.
* This class supply some method to read a document.
*
*/
public class XMLParser {
/**
* Get a instance of Document from a string of xml.
*
* @param xmlStr
* @return Document
*/
public static Document parse(String xmlStr) {
if (xmlStr == null) {
return null;
}
StringReader reader = new StringReader(xmlStr);
InputSource sourc ......
/*Decryptor*/
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
/**
* Decrypt the password get form Xpress GUI
*/
public class Decryptor{
//加密
private static byte[] encrypt(int mode, byte[] password) {
try {
DESKeySpec desKeySpec = new DESKeySpec("KEY".getBytes());
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(mode, secretKey);
return cipher.doFinal(password);
} catch (Exception e) {
return password;
}
}
//解密
public static String decrypt(String[] args) {
int length = args.length;
......
先贴代码吧
感谢:http://xranming.blog.163.com/blog/static/24204952009914104148872/
http://www.diybl.com/course/3_program/java/javajs/20090303/157541.html
1、java代码:
主要采用dom来进行操作
java对xml操作有四种方法:http://passmatlab.bokee.com/3455905.html
package test;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
public class XmlOprate {
Document doc;
DocumentBuilderFactory factory = Docu ......
java访问。net的webservice 而且 返回值是一个类,这玩意折磨我一天,出现过一系列的问题,
包括 没有定义SoapAction 不能序列化类等等。 最后还是服务提供商给了个demo,解决了 ,原因是我返回自定义类的一个变量没有get函数,可耻啊。而且demo里的代码 我想也是用wsdd2java生成的,我以前也看到过这种模式的实现,看着费劲。
整理了一下,如下:
private static String endpoint = "http://***/SmsService.asmx";
private static String nameSpace = "http://***.org/";
Service service = new Service();
call = (Call) service.createCall();
// 定义服务器地址
call.setTargetEndpointAddress(new java.net.URL(endpoint));
&nb ......
对于10进制数转换为N(2-36)进制一般都是选择取余除的算法进行转换 ,下面给出两种方案
一种是递归,一种是迭代。通过效率评价两者性能
其中迭代的方案直接取自java源代码。
/*
*Class NotationConvert.java
*Create Date: 2009-11-12
*Author:a276202460
*/
package com.rich.notation;
public class NotationConvert {
private static final String[] letters = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i",
"g", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z" };
static final char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z' };
public static String TentoN(int value, int number) {
if (number <= 1 || number > letters.length) {
throw new RuntimeException("Faild");
}
if (value < 0) {
return "-" + TentoN(0 - value, number); ......