【发布时间】:2014-06-15 02:35:35
【问题描述】:
我正在从事实时项目。
工作: 我从 twitter 获取数据并将输出移动到 cassandra 数据库,然后使用 Testrestfull webservice 我得到 json 格式的输出。然后最后输出显示在 wep 页面中。我正在使用玻璃鱼服务器连接网络服务和网页。这是一个实时项目,所以我每 5 秒刷新一次页面。
前几秒钟我没有收到任何错误,5 到 10 分钟后我在 glass fish 服务器中收到此错误。
错误: 警告:StandardWrapperValve [genric.ApplicationConfig]:Servlet genric.ApplicationConfig 的 Servlet.service() 引发异常 java.lang.OutOfMemoryError: Java 堆空间
我不知道为什么会出现此错误以及如何解决此问题。 谁能帮帮我。
这是我的网络服务代码:
public String gettweets(String st)
{
cluster=Cluster.builder().addContactPoint("localhost").build();
session=cluster.connect("space");
String query ="select * from tweet_count where createdtime='"+st+"' allow filtering;";
ResultSet result = session.execute(query);
String text = "[";
for(Row r : result){
System.out.println(r.getString("tag_name"));
text+="{\""+"x"+"\":\""+r.getString("tag_name")+"\",\""+"y"+"\":\""+r.getInt("count")+"\"},";
}
text=text.substring(0,text.length()-1);
text+="]";
return text;
}
这是我的网页代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body onload="load();grid();marqueeload();" style="background-color:white">
<pre style="height:25px;background-color:black;">
<div id = "title" style = "text-align:center;font-size:20px;width:100%;"><span>REAL TIME TWITTER TRENDS</span></div>
</pre>
<div><table>
<tr><td><lable>Select Date<lable></td><td> : </td><td><input id="datepicker" type="text" /></td></tr></table>
</div>
<div style = "width:100%">
<div id="container2" style = "width:670px;height:300px;float:left;background-color:white;border: 1px solid green;">
<div style = "text-align:center;font-size:20px;"><span1>CHART VIEW<span1></div>
<div id="container1"></div>
</div>
<div id="container3" style = "width:670px;overflow-y:auto;height:300px;float:right;background-color:white;border: 1px solid green;">
<div style = "text-align:center;font-size:20px;"><span1>GRID VIEW<span1></div>
<div id="Grid"></div>
</div>
</div>
<div style = "width:100%;border: 1px solid green;height:300px;float:left;background-color:white;">
<div style = "text-align:center;font-size:20px;"><span1>Trending tweets<span1></div>
<marquee id = "marqueeid" direction="up" height="200" scrollAmount=2 scrollDelay=130 class="sidelink" onMouseDown="this.stop()" onMouseOver="this.stop()" onMouseMove="this.stop()" onMouseOut="this.start()" vspace="10" >
</marquee>
</div>
<script type="text/javascript" language="javascript">
function marqueeload()
{
var str;
$.get("http://localhost:8080/WebApplication1/webresources/generic", function(str)
{
str=str.slice(12, str.length-14);
var div=document.getElementById('marqueeid');
div.innerHTML=str;
});
}
$(function () {
$("#datepicker").ejDatePicker({
select: "onSelected"
});
$("#datepicker").ejDatePicker({ enabled: true });
});
function onSelected(args) {
var str = args.value;
var newstr = str.split("/",3);
if(newstr[0].length == 1){
newstr[0] = '0'+newstr[0];
}
if(newstr[1].length == 1){
newstr[1] = '0'+newstr[1];
}
var dat = newstr[2]+'-'+newstr[0]+'-'+newstr[1];
window.datetweet = dat;
$("#container1").ejChart("destroy");
grid();
load();
}
function load() {
var str;
$.get("http://localhost:8080/WebApplication1/webresources/time/"+window.datetweet, function(str)
{
str=str.slice(12, str.length-14);
var data=JSON.parse(str);
$("#container1").ejChart(
{
primaryXAxis:
{
title: { text: 'Tagname' },
labelRotation: 45
},
primaryYAxis:
{
range: { min: 0, max: 1000, interval: 100 },
title: { text: 'Count' }
},
commonSeriesOptions: {
type: 'column', animation: true,
tooltipFormat: "#point.x# : #point.y#"
},
series: [
{
points: data,
}
],
load:"loadTheme",
showTooltip: true,
needResize:true,
size: { height: 300 },
legend: { visible: false, position: 'top' }
});
});
}
$(document).ready(function()
{
$("#Grid").ejGrid({
dataSource: [],
allowPaging: true,
allowSorting: true,
columns: [
{ field: "x", headerText: "Trend Name", textAlign: ej.textAlign.Right, width: 10 },
{ field: "y", headerText: "Count", textAlign: ej.textAlign.Right, width: 10 }
]
});
});
function grid()
{
var str;
var url="http://localhost:8080/WebApplication1/webresources/time/"+window.datetweet;
$.get(url, function(str)
{
str=str.slice(12, str.length-14);
var obj=JSON.parse(str);
var instance = $("#Grid").ejGrid("instance");
instance._dataManager = new ej.DataManager(obj);
$("#Grid").ejGrid("model.dataSource", instance._dataManager);
});
}
window.setInterval(function() { load(); grid(); marqueeload(); }, 10000);
</script>
</body>
</html>
【问题讨论】:
-
我猜你内存中的对象太多了……你应该配置内存设置;很快……你可以使用类似的东西:-Xms750m -Xmx2048m -XX:MaxPermSize=1024m 当你启动你的应用程序时
-
您可能需要检查内存泄漏。打印完整的堆栈跟踪以检查原因。
-
与您的情况类似的最常见原因可能是输入/输出流中的资源泄漏,但如果您需要任何进一步的帮助,则需要发布您的源代码。
-
我发布了源代码...你能帮我吗@Ceiling
-
一旦你认为你已经完成了你在
session=cluster.connect("space");打开的openend会话对象的操作,尝试调用session.close()来释放资源。
标签: java memory glassfish size heap-memory