954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Optimization

How can a Java program be optimized? I have no experience in this thematic so I could use some key words so I acn go deeper into it!
Thanks

rinko
Newbie Poster
12 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

There is no specific answer to this question, so I'll give you a general one..
First find out what need to be optimized? For this you can use tools like Rational/IBM Quantify (license issues) or Mocking Framework (in this you'll need to write some code of your own).
Once you know what has to be optimized, you can ask a specific question, then we can write more specific answers. :)

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

a mocking framework won't tell you what needs optimising.
A profiler may, but not a mock object (if anything it will likely hide the reason for any performance problems).

Most often when people "optimise" code they are just guessing where the problems are, grasping at straws and doing things they once heard someone say would make things faster (and usually they don't of course).

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
Most often when people "optimise" code they are just guessing where the problems are, grasping at straws and doing things they once heard someone say would make things faster (and usually they don't of course).


Not always true -- well maybe true for beginners who think their code needs optimization for no good reason other than the thing that 'optimization' is a cool word. Take for example String and StringBuffer class in scenarios where appending is frequent. Same thing for Vector and ArrayList.

One should know where to look when it comes for optimization.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

I've seen highly experienced people go wrong on "optimisation" when they didn't know the underlying machine instructions being generated (and few people know those).
That was C of course, but in Java deep knowledge is often also needed to get beyond the blatantly obvious stuff.

Things like loop and callstack optimisation aren't all that well known to many people.
SQL optimisation is an especially black art...

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
a mocking framework won't tell you what needs optimising. A profiler may, but not a mock object (if anything it will likely hide the reason for any performance problems).


It's just a use of mocking framework that we've found.. you can put out a trace at entry and exit every function. The trace is supposed to have particular information (time for one).. run your program with it and put down the traces in excel or run an awk/shell/perl script and you'll have your performance report.. (that's the reason I mentioned you'll have to write some code of your own)..
The reason why I suggested this in the first place is I donno how accessible Rational Quantify (or otherlicensed tools) are to this guy.. if they aren't one can always work around it..
Finally, no tool tells you what to optimize (not even Quantify).. they just give you a report and then just go figure.. :)

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

nice, but how are you going to trace the time needed for the functionality you replaced by those mocks (which usually is the expensive stuff like database and network operations)?

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
nice, but how are you going to trace the time needed for the functionality you replaced by those mocks (which usually is the expensive stuff like database and network operations)?


You don't mock any objects ! Just define pointcuts for entry/exit of all classes/functions you wanna measure and add before()/after() to trace.
Will post teh code if possible.

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 
You don't mock any objects ! Just define pointcuts for entry/exit of all classes/functions you wanna measure and add before()/after() to trace. Will post teh code if possible.


I just put Narue's sorting algorithms thru a performance test.
Here is what the output looks like when I put it in an excel sheet.
Have posted the code used in code snippets . My first Java 5.0 code. :)

Attachments Output.jpg 61.11KB
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

Hi Kashyap,

Did you tested the functionality of AspectJ with Web Services ...? I used WSIF demo also but i'm facing various issues .If you have any documents or links pointing to this then please post it here.

Thanks

lucky1981_iway
Light Poster
46 posts since Apr 2007
Reputation Points: 10
Solved Threads: 3
 

>> Did you tested the functionality of AspectJ with Web Services ...?
Nope, this was my first aspect program. :)
Why don't you post your problem as a thread may be I/someone can help..

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You