Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧
darx





发贴: 25
积分: 0
于 2004-11-21 18:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我写的一个程序要求一天24小时运行
有三个文件
A.java,B.java和C.java

A.java负责启动和监视
B.java是主要运行的程序,实现了Runnable接口
C.java是具体执行的,实现了Runnable接口

我的思路是
B.java运行时要从外部读取数据,然后根据这些数据来创建C的实例,数据在C的run()中处理执行,执行完后C关闭
因为外部很多的不稳定因素,导致B读取数据时可能会出错,也可能超时,所以我用了A来监视B最后一次读取数据的时间,如果超过xx秒,就重新执行B

现在程序运行几个小时后就出现java.lang.OutOfMemoryError的内存漏洞错误
在控制台中不停显示 “B reboot”

大家帮我看看结构上有不有问题
程序代码太多,大概的结构是
class A{
....main(){
........B b = new B();
........while(true){
............if (System.currentTimeMillis() - B.lastTime > 15000) {
................b.go = false;
................b = new B();
................System.out.println("B reboot");
............}
............Thread.sleep(8000);
........}
....}
}

class B implements Runnable{
....lastTime = 0;
....go = true;
....B(){
........t = new Thread(this);
........t.start();
....}

....run(){
........while(go){
............从外部读取数据

............if(...){
................new C(...);
............}
............if(){
................new C(...);
............}
............lastTime = System.currentTimeMillis();
............t.sleep(1000);
........}
....}
}

class C implements Runnable{
....C(...){
........t = new Thread(this);
........t.start();
....}
....run(){
........处理数据
....}
}

大家帮帮忙,多谢




话题树型展开
人气 标题 作者 字数 发贴时间
25823 郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 1255 2004-11-21 18:06
23558 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 kavinwang 53 2004-11-21 18:15
23499 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 kavinwang 102 2004-11-22 16:19
23841 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 ftang 362 2004-11-23 02:10
23493 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 9 2004-11-23 21:42
23453 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 242 2004-12-05 22:37
23508 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 105 2004-12-07 10:32
23617 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 34 2004-11-21 20:22
23579 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 littledeer1974 64 2004-11-21 20:59
23662 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 137 2004-11-21 21:07
23562 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 littledeer1974 156 2004-11-21 21:26
23666 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 49 2004-11-21 21:36
23458 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 littledeer1974 32 2004-11-21 21:50
23854 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 63 2004-11-21 22:06
23611 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 littledeer1974 55 2004-11-21 22:12
23651 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 jameszhang 137 2004-11-22 08:19
23800 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 kavinwang 489 2004-11-22 08:50
23664 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 14 2004-11-22 09:56
23753 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 kavinwang 16 2004-11-22 11:34
23894 Re:郁闷了2天的一个关于OutOfMemoryError的问题,有空的进来帮帮忙看看吧 darx 200 2004-11-22 11:57

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923