Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Runs fast inside Eclipse, slow as runnable JAR
Runs fast inside Eclipse, slow as runnable JAR [message #1008132] Sun, 10 February 2013 18:10 Go to next message
Chris Crawford is currently offline Chris CrawfordFriend
Messages: 7
Registered: January 2012
Junior Member
I'm a long-time, very simple-minded programmer who uses perhaps 10% of the capabilities of Eclipse; I've been using Eclipse for maybe five years now and have assiduously avoided learning anything that I don't need. I've been exporting projects to runnable JAR files for years with no problems. But I have run into a nasty little issue. I don't know if it's an Eclipse problem or a Java problem. I'm running on a Mac Pro, OS 10.7.5.

I have some big images (128w by 128h) that I'm treating as simple graphics objects rather than JButtons, for complicated reasons. I need to replicate SOME of the behavior of JButtons, including the redrawing of the image when the pseudo-button is pressed. This is handled with a very simple bit of code inside the mousePressed() method of the Mouse Listener:

  int i=0; 
  boolean gotcha=false;
  while ((i<cButtons)&(!gotcha)) {
	  if (buttons[i].fEnabled) {
		  Rectangle test=new Rectangle(buttons[i].x,buttons[i].y,faceWidth,faceHeight);
		  if (test.contains(e.getX(), e.getY())) {
			  gotcha=true;
			  buttons[i].fPressed=true;
			  repaint(buttons[i].x,buttons[i].y,faceWidth,faceHeight);
		  }	
	  }
	  ++i;
  }


The value of cButtons is 16, so the loop executes a maximum of 16 times; in this test case, only seven buttons get past the first if-test. faceWidth and faceHeight are equal to 128.

When I run the program inside Eclipse, everything runs just fine, but when I export it to a Java runnable file, with "Package required libraries into generated JAR", and run the result, I get a problem: the buttons blink. That is, the repainting process takes so long that erasing the background takes an entire frame jiffy and drawing the button takes more than one frame jiffies. It gets worse: the length of the blink is visibly concomitant with the position of the button in the array. That is, the first three buttons on the screen are drawn without blinks, the fourth has a very short blink, the fifth a visibly longer blink, and the sixth even longer. In other words, this code is requiring at least 5 milliseconds per loop iteration, and possibly as much as 20 milliseconds per loop iteration. That's ridiculous! This is running on a Mac Pro with two 2.66 GHz dual-core processors and over 3 GB of free RAM according to the Activity Monitor.

Why is it running so slowly as a runnable JAR when it runs so fast inside Eclipse? We'd expect that Eclipse would slow it down, if anything. I fear that my problem lies in some magical incantation I have to perform with Eclipse to tell it to prepare the final code in a manner that runs quickly.

Any suggestions as to what I'm doing wrong?
Re: Runs fast inside Eclipse, slow as runnable JAR [message #1008944 is a reply to message #1008132] Thu, 14 February 2013 07:32 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4165
Registered: July 2009
Senior Member

You're certain you're running it with the same JRE both in and out of Eclipse?

Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Runs fast inside Eclipse, slow as runnable JAR [message #1723933 is a reply to message #1008132] Fri, 19 February 2016 07:15 Go to previous messageGo to next message
anudeep arya is currently offline anudeep aryaFriend
Messages: 49
Registered: March 2013
Member
Hello All,

I am facing the same issue now.I have build the JAR in jre8 and the default java version in my windows machine is also 1.8.

Any idea how this issue can be resolved.

Regards,
Anudeep.

Re: Runs fast inside Eclipse, slow as runnable JAR [message #1848933 is a reply to message #1008132] Fri, 24 December 2021 05:00 Go to previous message
Krishna Karur is currently offline Krishna KarurFriend
Messages: 1
Registered: December 2021
Junior Member
The problem here is that you are selecting "Package required libraries into generated JAR" while creating the JAR from Eclipse. When we do this, all the dependencies JARs are packaged along with your code into the created JAR file. Due to this, all the dependencies must be extracted from the JAR file each time there is a reference to any of the dependencies - Hence the long time for execution.

I suggest - Use the option "Extract required libraries into generated JAR" while generating the Runnable JAR file. By doing this, the execution time for the jar file is exactly same as it would take if you run the same project from eclipse.

Peace! Good Luck,
Krishna.
Previous Topic:Autocomplete is not working for jsf pages
Next Topic:There is no stable version of eclipse in the futureļ¼Ÿ
Goto Forum:
  


Current Time: Sun Jan 23 07:02:09 GMT 2022

Powered by FUDForum. Page generated in 0.04622 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top