Java Eclipse问题总结

1.Remote Debug

步骤

1.启动程序时,添加参数
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=7899,suspend=n

-XDebug 启用调试;
-Xrunjdwp 加载JDWP的JPDA参考执行实例;
transport 用于在调试程序和VM使用的进程之间通讯;
dt_socket 套接字传输;
server=y/n VM是否需要作为调试服务器执行;
address=7899 调试服务器监听的端口号;
suspend=y/n 是否在调试客户端建立连接之后启动 VM

2.先在程序中打好断点,然后

Run–>Debug Configurations…–>Remote Java Application–>右键New–>填写Host和Port(例如,Host:10.75.0.103,Port:7899)–>Debug

其余与本地debug类似

variable颜色代表的意义

蓝色三角:类中定义的变量
红色方块:私有方法定义
绿色实心圆:公有方法
黄色实心菱形:protected修饰的方法
小黄色空心菱形:protected变量
空心绿色圆环:公有定义变量
红色字符S随后:静态

step into/step over/step return

step into就是单步执行,遇到子函数就进入并且继续单步执行;

step over是在单步执行时,在函数内遇到子函数时不会进入子函数内单步执行,而是将子函数整个执行完再停止,也就是把子函数整个作为一步。

step return就是单步执行到子函数内时,用step return就可以执行完子函数余下部分,并返回到上一层函数。

step into:进入子函数

step over:越过子函数,但子函数会执行

step return:跳出子函数

2.build GC overhead limit exceeded/java heap space

解决方法

将eclipse.ini文件的最后两行,一般默认为
-Xms40m
-Xmx512m
修改为
-Xms512m
-Xmx1024m

原因

The Java.lang.OutOfMemoryError: GC overhead limit exceeded error means that the GC tried to free memory but was pretty much unable to get anything done. By default it happens when the JVM spends more than 98% of the total time in GC and when after GC less than 2% of the heap is recovered.
——[GC overhead limit exceeded]

GC试图回收内存,但是什么也没有回收到。默认情况下,JVM花费了98%的时间在GC上,但是GC过之后只有不到2%的堆内存被回收。

如果没有这个GC overhead limit会发生什么现象:
What would happen if this GC overhead limit would not exist? Note that the java.lang.OutOfMemoryError: GC overhead limit exceeded error is thrown only when 2% of the memory was freed after several GC cycles. This means that the little amount GC was able to clean will be quickly filled again, forcing GC to restart the cleaning process again. This forms a vicious cycle where the CPU is 100% busy with GC and no actual work can be done. End users of the application face extreme slowdowns – operations which normally complete in milliseconds take minutes to finish.
——[GC overhead limit exceeded]

简单来讲,就是一次GC过后,并没有回收到内存,很快又会进行GC,极端情况下会循环GC(关键是并没有回收到可用内存),从而导致CPU100%负载。

属性

Xms JVM的初始堆大小
Xmx JVM的最大堆大小
当最小堆被占满后,会进行GC,如果GC之后还不能得到足够的内存,就会扩展堆,最大扩展至Xmx设定的值。

可以添加一行"-XX:MaxPermSize",在编译文件的时候就让它一直最大限度占有内存

3.无法自动编译

选中project->build automatically后无法自动编译,取消后手动编译也不行,可能是项目里引了某个不用的jar包,而那个包又被你删了,就会出现不报错但怎么也编译不出来class文件的情况,可以把所有包都删除,然后一个一个的再引入,不要一下子把所有包都引入来,没用的可能会引起不良后果

发布了43 篇原创文章 · 获赞 31 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/devil_bye/article/details/81665920