Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Concurrency, Threading, GC, Advanced Java and more ...
Tips July 29th, 2003
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 032 contents
At JavaPerformanceTuning.com, we scan the internet for any articles with interesting
Java performance information. When we find one, we add it to our
huge article list,
but we also extract the performance tips from those articles, and list
those extracted tips in our newsletter. Below, you can see this month's extracted
tips.
http://www.javaspecialists.co.za/archive/Issue070b.html
Multidimensional arrays are slow (Page last updated May 2003, Added 2003-07-29, Author Heinz Kabutz, Publisher Kabutz). Tips:
- Multidimensional array creation is slower than single dimension array creation.
http://www-106.ibm.com/developerworks/java/library/j-jtp04223.html
Performance legends (Page last updated April 2003, Added 2003-07-29, Author Brian Goetz, Publisher IBM). Tips:
- Uncontended synchornization is not significantly slower than unsynchronized execution.
- Declaring classes or methods
final
does not improve performance.
- Immutable objects can be good or bad for performance depending on how they are used: Immutable objects do not need to be defensively copied; but immutable objects must be copied for any changes.
- Optimize with concrete performance goals in mind. Use clean correct design, and performance tune only when a performance problem is identified.
- Don't assume that performance tips are still valid. They may have passed their "use by" date.
http://www.sys-con.com/java/article.cfm?id=1989
J2EE design (Page last updated May 2003, Added 2003-07-29, Author Ajit Sagar, Publisher JavaDevelopersJournal). Tips:
- In an ideal project, while each module is designed it's performance characteristics are considered.
- A proof of concept is geared toward demonstrating functionality; A prototype should be an implementation of the full solution that tests minimal functionality. A proof of concept doesn't need to consider performance characteristics, while a prototype should tweak out performance characteristics before the full functionality is implemented.
http://developer.java.sun.com/developer/JDCTechTips/2003/tt0624.html
Generating Diagnostics by Monitoring the System Event Queue (Page last updated June 2003, Added 2003-07-29, Author John Zukowski, Publisher Sun). Tips:
- Attaching a listener to the system event queue will slow down your application's operations, as every event sourced from a Component or MenuComponent is checked against your listener.
- If the task you want to perform is not very quick, you should create a secondary thread to perform the operation.
http://www-106.ibm.com/developerworks/ibm/library/i-incrcomp/
Incremental compaction in the IBM JDK Garbage Collector (Page last updated June 2003, Added 2003-07-29, Author Aruna Kalagnanam, Sripathi Kodi, Publisher IBM). Tips:
- [Article includes tables to interpret verbosegc output for IBM JVM].
- Running with incremental compaction seems to provide better performance: -Xpartialcompactgc runs an incremental compaction every GC cycle (default value is false); -Xnopartialcompactgc makes the JVM never run an incremental compaction (default value is false).
http://www.javaworld.com/javaworld/jw-06-2003/jw-0606-wireless.html
High-availability mobile applications (Page last updated June 2003, Added 2003-07-29, Author Michael Juntao Yuan , Publisher JavaWorld). Tips:
- On-device databases can provide a performance cache to reduce network roundtrips, which could drastically improve application performance.
- Mobile databases have proprietary features which can help provide better performance for J2ME applications.
http://www.informit.com/isapi/product_id~{9AA6BD2C-DC80-4583-BEDD-D3930D303F06}/content/index.asp
Concurrency in Java (Page last updated May 2003, Added 2003-07-29, Author Bruce Eckel, Publisher Prentice Hall). Tips:
- Concurrency can be used to produce a responsive user interface and to optimize throughput by parallelizing tasks.
- Thread.yield( ) is useful only in rare situations, and you can't rely on it to do any serious tuning of your application.
- java.util.Timer is designed to scale to large numbers of concurrently scheduled tasks (in the thousands).
- To solve the problem of thread collision serialize access to shared resources.
- In the JVM an increment is not atomic and involves both a read and a write.
- In JDK 1.3 and 1.4 (and up) the overhead of synchronized has been greatly reduced only remove synchronization after using a profiler to determine that synchronized is indeed the bottleneck.
http://www.ociweb.com/jnb/jnbJul2003.html
Generics in Java (Page last updated July 2003, Added 2003-07-29, Author Rob Smith, Publisher OCI). Tips:
- There is no performance penalty from using generics.
- There is no performance boost from generics.
Tips for the week ending 4th July 2003
Continuing from last month's focus on JavaOne presentations, we extract
tips from a few more of those presentations this week
http://servlet.java.sun.com/javaone/resources/content/sf2003/conf/sessions/pdfs/1493.pdf
Taking Advantage of the Java 2D API in your Rich Client Application (Page last updated June 2003, Added 2003-07-03, Authors Jim Graham, Shannon Hickey, Chris Campbell, Publisher Sun). Tips:
- Using Timers is the preferred method of animation in Swing
- Notifications come on the event thread; you don't need to worry about Swing threading issues.
- Use Timer class: "Timer timer = new Timer(1000, new ActionListener {...}); timer.start();"
- Two ways to use Timers for animation: Animation driven by Timer ticks (update frame each time event received); Animation driven by time (calculate elapsed time each time event received, and update frame if elapsed time has incremented by frame rate).
- For image scaling set hints: "Graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // or VALUE_INTERPOLATION_NEAREST_NEIGHBOR". Nearest neighbour is the default and is fastest, interpolation is smoother but slower.
- Gradients (pretty backgrounds) used with Graphics2D.setPaint(new GradientPaint(int x1, int x2, Color col1, int x2, int y2, Color col2, boolean cyclic))". Keep last "cyclic" parameter "true" for good performance (unless you need a non-cyclic gradient).
http://servlet.java.sun.com/javaone/resources/content/sf2003/conf/sessions/pdfs/1402.pdf
Java Technology for Game Developers (Page last updated June 2003, Added 2003-07-03, Authors Chet Haase, Dmitri Trembovetski, Doug Twilleager, Publisher Sun). Tips:
- ManagedImage is faster than BufferedImage because the ManagedImage is mapped by hardware. Create Managed Images using Component.createImage()/GC.createCompatibleImage()/Toolkit.getImage()/ImageIcon.getImage().
http://servlet.java.sun.com/javaone/resources/content/sf2003/conf/sessions/pdfs/2302.pdf
Detecting and Solving Common J2EE Application Performance Problems (Page last updated June 2003, Added 2003-07-03, Author Charles Palczak, Publisher Sun). Tips:
- Tuning Methodology: Measure performance; Identify the problem; correlate the problem across tiers; Tune only if the performance problem is significant enough.
- Collect data such as URLs and SQL statements along with other measurements.
- Common J2EE Performance Problems: Database connection pool too small; JNDI Lookup calls not cached; Long running SQL; Too many database round-trips; Container Managed Persistence (CMP); Entity Bean transaction scope too fine.
- Database Connection Pool Too Small: Tuning advice is that if the total contribution of getConnection() to the response time is more than 1%, then increase the size of the database connection pool.
- JNDI Lookup Calls Not Cached: Tuning advice is that if the total contribution of lookup() to the response time is more than 4% then change Java code to cache the lookup() call.
- Long Running SQL: Tuning advice is to find the long running SQL calls and tune the SQL or tune the database or tune both.
- Too Many Database Round Trips: Tuning advice is to inspect the relative frequency of JDBC calls, and consider tuning application logic to make fewer calls.
- CMP Entity Bean Transaction Scope Too Fine: Tuning advice is that if an entity bean?s persistent state is synchronized more than once when invoked from a session bean, then enlarge the transaction scope at the session bean instead of at the entity bean.
http://servlet.java.sun.com/javaone/resources/content/sf2003/conf/sessions/pdfs/2165.pdf
Dispelling the EJB Architecture CMP Performance Myths (Page last updated June 2003, Added 2003-07-03, Authors Michael E. Bouchard, Lora C. Wallace, Publisher Sun). Tips:
- Data-Centric Systems can increase performance by moving business logic closer to the data.
- Object-Centric Systems can increase performance by moving data closer to the objects.
- Minimize the round-trips required to obtain data from the database.
- [Article covers several case-studies of deployed systems with high performance].
- Extreme performance needs where EJBs may be inappropriate: Batch inserts; Complex object-graph caching; Existing DB schema not conducive to object-model.
http://servlet.java.sun.com/javaone/resources/content/sf2003/conf/sessions/pdfs/3588.pdf
Java Technology Design Patterns for High-Load Web Sites (Page last updated June 2003, Added 2003-07-03, Authors Leon Shklar, John Burket, Publisher Sun). Tips:
- WSJ.com uses Java Technology to serve 700,000 subscribers and millions of page views per day
- Speeded authorization by Servlet placing a permission bitmap inside login cookie that is later decrypted by web server plugin
http://servlet.java.sun.com/javaone/resources/content/sf2003/conf/sessions/pdfs/3420.pdf
Optimizing XML Processing for Performance (Page last updated June 2003, Added 2003-07-03, Authors Rob Ruyak, Lalit Mathwani, Biswadeep Nag, Publisher Sun). Tips:
- [Article compares DOM/SAX/JAXB performance for a number of different functions]
- SAX is best choice for single pass processing (parsing and validation); DOM can build document trees quickly; JAXB is very effective for element access.
- Beware of expensive operations: getElementsByTagName in DOM; marshall in JAXB.
- Popular XML Schema design techniques (Russian Doll, Salami Slice, Venetian Blind) don?t have major performance implications (i.e none are significantly more efficient).
Jack Shirazi
Back to newsletter 032 contents
Last Updated: 2025-01-27
Copyright © 2000-2025 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/newtips032.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us