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 2007
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 080 contents
http://www.fasterj.com/articles/crays.shtml
Cray Reminiscences (Page last updated July 2007, Added 2007-07-31, Author Kirk Pepperdine, Publisher Fasterj.com). Tips:
- For better system performance Windows users can eliminate the pagefile from their machines if they have plenty of real RAM.
- The order of nesting when iterating through multidimensional arrays affects performance - the right most index should be iterated in the most tight loop.
- Lock contention starves threads from obtaining the CPU, and puts pressure on the operating system - there is nothing quite as disruptive to a processor as having to execute code to acquire a lock.
http://developers.sun.com/mobility/midp/articles/imagecache/
Implementing a Local Cache to Manage Resources (Page last updated June 2007, Added 2007-07-31, Author C. Enrique Ortiz, Publisher Sun). Tips:
- Keeping resources within a MIDlet suite can be expensive in terms of application size.
- To minimize the size of a MIDlet, download resources the first time the application runs or on-demand and store the resources locally for later use.
- Using a resource cache can reduce the overall MIDlet suite size.
- The image cache: Attempts to retrieve the resource from memory; If not in memory, tries to load it from storage; If not in storage, it dispatches a thread to load it from the network.
- ImageCache and ImageCacheListener are about 17 Kilobytes in size, qhich is smaller than embedding a number of static images within the MIDlet suite.
- [Article includes an implementation of an ImageCache class]
- A possible ImageCache enhancement is to add expirations to loaded images so that rarely accessed images are removed from the handset and reloaded when needed, helping maximize memory and storage utilization.
- If the sum of all the resources to be consumed by an application is less than the size of the caching system, and/or the application doesn't require support for resource updates on the field, then using the caching system might not be necessary.
http://cretesoft.com/archive/Issue146.html
The Secrets of Concurrency (Part 1) (Page last updated June 2007, Added 2007-07-31, Author Dr. Heinz M. Kabutz, Publisher Java Specialists' Newsletter). Tips:
- A thread is interrupted when another thread calls its interrupt() method. This sets the interrupted status of the thread to true, and will cause an InterruptedException to be thrown immediately (if the thread is waiting) or later (when the thread next waits).
- Examples of methods that put a thread into a WAITING or a TIMED_WAITING state are: wait(), Thread.sleep(), BlockingQueue.get(), Semaphore.acquire() and Thread.join().
- If a thread is not in the WAITING or TIMED_WAITING states, then having it's interrupt() method called simply sets its interrupted status to true, and nothing else happens. However any method that subsequently puts the method into a WAITING or TIMED_WAITING state will cause an immediate InterruptedException to be thrown.
- If a thread is in the WAITING or TIMED_WAITING states, then having it's interrupt() method called immediately causes an InterruptedException to be thrown.
- synchronized puts the thread in BLOCKED state, not in WAITING nor TIMED_WAITING. Interrupting a blocked thread does nothing except set the interrupted status to true.
- A thread's interrupted status is set to false when an InterruptedException is caused or when the Thread.interrupted() method is explicitely called.
- If you are not dealing with the interrupt directly, you should pass it on to the calling method by resetting the interrupt status, e.g. by calling Thread.currentThread().interrupt().
http://www.theserverside.com/tt/articles/article.tss?l=NoObjectsLeftBehind
No Objects Left Behind (Page last updated July 2007, Added 2007-07-31, Author Kirk Pepperdine, Publisher theserverside). Tips:
- Advice suggesting reducing the size of the survivor spaces so that objects get immediately promoted to the old generation is probably wrong. Making survivor spaces large to delay promotion to old space is probably better advice.
- verbose GC logging with the standard flag -verbose:gc provides a basic level or GC monitoring.
- The most reliable way to release objects as soon as possible is to narrow their scope: Move statically scoped variables to be instance based; Move instance based variables to local scoping; Ask if you can we eliminate some variables altogether; Is the design forcing data to be held on to for longer than is necessary.
- The GC algorthms are improving all the time, so make sure you reanalyse garbage collection and the settings you use in your apps occassionally.
http://www.softwareprojects.com/resources/programming/t-optimize-website-performance-1354.html
Optimize website Performance (Page last updated July 2007, Added 2007-07-31, Author Mike Peters, Publisher softwareprojects). Tips:
- Optimize using the principle that reads are cheap and writes are expensive.
- Sudden huge spikes in traffic are common, e.g. when a page suddenly becomes referred to by news sites.
- Apache+PHP is a resource hog.
- Minimize the number of queries and connection time required to handle every request
- Switch everything possible to offline processing
- Use replication to improve scalability and service reliability
- generate static HTML where possible
http://weblogs.java.net/blog/mlam/archive/2007/06/async_thread_du.html
Async Thread Dumps on CVM (Page last updated June 2007, Added 2007-07-31, Author Mark Lam, Publisher java.net). Tips:
- [Article provides a code patch that installs a stack dumping SIGQUIT signal handler to the CVM].
http://weblogs.java.net/blog/sdo/archive/2007/07/switching_track.html
Performance Of Alternative Switch Bytecodes (Page last updated July 2007, Added 2007-07-31, Author Scott Oaks, Publisher java.net). Tips:
- Java contains two different bytecodes for switch statements: a generic switch statement, and an (allegedly more optimal) table-driven switch statement. There may be no significant difference in performance between the two - if in doubt, test your specific case.
- [Article shows a real-world example where the cost of converting the data was as much as the cost of the switch, so there would be only a small benefit anyway in altering which switch to use].
http://www.artima.com/forums/flat.jsp?forum=276&thread=210972
Singletons, Good Or Bad? (Page last updated July 2007, Added 2007-07-31, Author Frank Sommers, Howard Lovatt, Steve Merrick, Publisher Artima). Tips:
- Singletons introduce global state into a program - programs using global state are very difficult to test.
- Programs that rely on global state (like Singletons) hide their dependencies.
- If there is really only one of something in the system then the singleton is a good choice.
- In distributed environments, trying to create and use a Singleton is probably more trouble than it's worth.
- Accessing Singletons through a static method each time may allow the application to later change the object returned depending on context
Jack Shirazi
Back to newsletter 080 contents
Last Updated: 2024-08-26
Copyright © 2000-2024 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/newtips080.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us