Linux 下 Java 开启 OpenGL 技巧

在我的系统上每次使用 Java 应用程序时,我都感觉特别慢。对于一些比较大的 Java 应用程序而言,这种感觉尤其明显。最近,我学到了一招技巧,提速的效果还不错。如果你也有类似的烦恼,那么赶紧来试试吧。

要使用该技巧,你必须满足以下条件:

  1. 开启 OpenGL 3D 加速的显卡
  2. Sun Java version 5 及更高版本

说来也简单,你只需在 Java 应用程序的启动命令中加入如下选项即可:

-Dsun.java2d.opengl=true

这样,该 Java 应用程序就会使用 OpenGL 硬件加速来进行渲染。

以 FreeMind 为例,通过编辑其安装目录下的 freemind.sh 启动脚本,可以加入上面的选项(大约在 209 行左右)。

{ via Ubuntu Forums }

Read More:

23 Comments

  1. 1 Rothsdad Commented @ 2009-04-22 11:00Reply to this comment

    效果不错,谢谢分享!

  2. 2 GenTux Commented @ 2009-04-22 11:24Reply to this comment

    如果是二进制文件呢?

  3. 3 store88 Commented @ 2009-04-22 11:34Reply to this comment

    是否可以加入java的系统环境中呢

  4. 4 ggyy_sun Commented @ 2009-04-22 11:41Reply to this comment

    Firefox 3.0.9发布了,Toy赶紧的出消息呀

  5. 5 bb Commented @ 2009-04-22 12:45Reply to this comment

    好像eclipse用这个效果不是很好(debian testing, sdk5)

  6. 6 su27 Commented @ 2009-04-22 13:15Reply to this comment

    确实有效,多谢

  7. 7 黑传说 Commented @ 2009-04-22 13:34Reply to this comment

    xmind,没做优化,速度还不错。freemind确实需要优化才能称得上:思维导图

  8. 8 gchuyun Commented @ 2009-04-22 14:24Reply to this comment

    不知道 alias java='java -Dsun.java2d.opengl=true' 有没有效果

  9. 9 GenTux Commented @ 2009-04-22 15:08Reply to this comment

    'java -Dsun.java2d.opengl=true' 这句命令在只有JRE的环境下根本不能执行啊

  10. 10 Alex Commented @ 2009-04-22 15:09Reply to this comment

    上面这位的写法是错的. 别人如果加了其他参数你就运行不了了. 建议这篇文章标题改为linux 下java开启opengl 技巧.

  11. 11 Mike Commented @ 2009-04-22 15:30Reply to this comment

    intel显卡是不可以的。 只有n卡才可以。

  12. 12 xqh Commented @ 2009-04-22 18:51Reply to this comment

    果然快了很多,谢谢

  13. 13 fcicq Commented @ 2009-04-22 21:19Reply to this comment

    同10楼的同学... toy 同学看见的话还是改题目吧 :D

  14. 14 ginkgo Commented @ 2009-04-22 22:09Reply to this comment

    开了这个,有时候会有兼容性问题。

  15. 15 hantsy Commented @ 2009-04-23 0:09Reply to this comment

    提速??? 第一感觉应该调jvm 参数。

  16. 16 larz Commented @ 2009-04-23 15:16Reply to this comment

    @bb: eclipse用SWT绘制介面,而SWT是native widget的wrapper,因此无法从java2d的提速获益

    说起来SUN还是把java的重心放在win平台上,java2d在jdk1.4就默认开启d3d加速,而jdk1.5新增opengl加速,但默认是关闭的,因此大型的java桌面应用在非win平台的使用者体验均较差

  17. 17 Ivan Chen(西滨) Commented @ 2009-04-25 9:35Reply to this comment

    @gchuyun: 可以设置环境变量: export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dsun.java2d.opengl=true ' 这个是对所有的java程序都生效的。注意_JAVA_OPTIONS有下划线。

  18. 18 Ivan Chen(西滨) Commented @ 2009-04-25 9:37Reply to this comment

    晕,留言不能有英文下划线?JAVAOPTIONS应该是“下划线JAVA下划线OPTIONS”

  19. 19 Toy Commented @ 2009-04-25 10:06Reply to this comment

    @Ivan Chen(西滨): 在 _ 前加 \ 即可正常显示。

  20. 20 Chainet Commented @ 2009-04-30 12:10Reply to this comment

    设置 -Dsun.java2d.opengl=true 后,永中Office 2009个人版不稳定,经常crash。

  21. 21 Terry Wang Commented @ 2009-05-05 9:16Reply to this comment

    自己早年写的一个程序启动脚本中加入参数后,启动确实比原来快了。Great tip!

  22. 22 Terry Wang Commented @ 2009-05-11 13:08Reply to this comment

    More info: http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html#ogl

  23. 23 muxueqz Commented @ 2009-05-16 11:07Reply to this comment

    哈哈,多谢啦 加速永中,果然很快!