Java官方的Logger.getGlobal().info无效
- 无效代码
Logger.getGlobal().info("start");
- 解决方案(三选一):
Logger.getLogger("global").setLevel(Level.INFO)
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info("start");
Logger.getLogger("global").info("start");
JAVA线程加载图片挂在 java.awt.MediaTracker.waitForID
- 问题发生时打印的日志一般如下所示
"AWT-EventQueue-0" prio=10 tid=0x0811e400 nid=0x3d80 in Object.wait() [0xdeb95000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0xe651f1f8> (a java.awt.MediaTracker)
at java.awt.MediaTracker.waitForID(MediaTracker.java:651)
- locked <0xe651f1f8> (a java.awt.MediaTracker)
at javax.swing.ImageIcon.loadImage(ImageIcon.java:264)
- locked <0xe651f1f8> (a java.awt.MediaTracker)
at javax.swing.ImageIcon.<init>(ImageIcon.java:194)
- 该问题属于JDK Bug,加载图片有较小几率会挂死当前线程。而挂死了UI线程等于整个客户端都完蛋了。
- 解决该问题的思路:
- 首先用一个对象当锁。
- UI线程先启动线程A,然后synchronize锁并wait唤醒,可设超时时间。
- 线程A加载图片,在工作完成时synchronize锁并notify对象。
- 这样就算线程A挂死,也不影响UI线程的正常运行。
参考资料
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6995182
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4881229
控制台输出Unloading class
- 问题发生时控制台输出一般如下
[Unloading class sun.reflect.GeneratedMethodAccessor22]
[Unloading class sun.reflect.GeneratedMethodAccessor47]
[Unloading class sun.reflect.GeneratedMethodAccessor24]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor6]
[Unloading class sun.reflect.GeneratedMethodAccessor26]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor13]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor16]
- 原因可能是程序启动参数里含有
-Xloggc
参考资料
http://*.com/questions/2833983/meaning-of-the-unloading-class-messages
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7040410
SSH调用Windows下的Java程序提示版本异常
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.6' is required.
Error: Could not find java.dll
Error: Could not find Java SE Runtime Environment.
解决方案:
- 将C:\ProgramData\Oracle\Java\javapath从PATH环境变量中去除
- 在C:\Windows\System32目录下删除java、javaw、javaws
- 最根本的解决方法是安装JDK的时候不要勾选JRE
参考资料
http://*.com/questions/29697543/registry-key-error-java-version-has-value-1-8-but-1-7-is-required