简体   繁体   中英

Java program runs smoothly in Netbeans but slowly in Eclipse and as an executable jar

A java program that does frequent swing/awt painting animation (but nothing more advanced than g.fillOval(...)) runs at a consistent 60fps in Netbeans, and at about 6fps when ran in Eclipse or executed as a jar file from a unix terminal. The program was developed in Netbeans and is run-of-the-mill desktop application (not webstart or japplet or ...). This is occurring in Ubuntu 10 with java 1.6. How is this possible?

$ java -version
java version "1.6.0_22"

Java(TM) SE Runtime Environment (build 1.6.0_22-b04)

Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)


Set the default jvm to the sun version, and outputed the jvm used by netbeans and the unix terminal, which was the same for both:

java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386, java.vm.version=17.1-b03, java.vm.vendor=Sun Microsystems Inc.

However, this didn't make any difference as there is still a significant frame rate discrepancy. Is there some other factor that could be at play here?

One of possible reasons may be that NetBeans can use one JVM, and Eclipse and terminal "java" command can use another. Look into what platform NetBeans uses for your project, and compare it with Eclipse.

Also there can be something with arguments you passed to JVM. Check that too.

In Ubuntu there's a very handy utility. Try this:

sudo update-java-alternatives -s java-6-sun 

in shell. It may output some errors...

update-alternatives: error: no alternatives for mozilla-javaplugin.so. 
update-alternatives: error: no alternatives for xulrunner-1.9-javaplugin.so. 
update-alternatives: error: no alternatives for mozilla-javaplugin.so. 
update-alternatives: error: no alternatives for xulrunner-1.9-javaplugin.so.

That's only a problem with java plugin for Firefox. You may ignore this. If you have any other problem, than check which java you've got installed by issuing:

sudo update-java-alternatives -l

Or, you may use the interactive version:

sudo update-java-alternatives --config

(... this one I haven't tested).

If for any reason You don't have Sun's JDK listed post a comment.


EDIT

Are you using hardware acceleration? Try adding this JVM property:

-Dsun.java2d.opengl=True 

To see details you might also use:

-Dsun.java2d.trace=log 

Consult OpenGL acc for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM