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 December 2011
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 133 contents
http://www.javaspecialists.eu/archive/Issue196.html
Uncaught AWT Exceptions in Java 7 (Page last updated November 2011, Added 2011-12-28, Author Dr. Heinz M. Kabutz, Publisher The Java Specialists' Newsletter). Tips:
- Bootstraping the GUI system with a thread that belongs to your own thread group allows you to catch uncaught AWT Exceptions.
- Registering a default uncaught exception handler lets you catch all the uncaught exceptions that happen from all threads (Thread.setDefaultUncaughtExceptionHandler) or any particular threads (Thread.setUncaughtExceptionHandler) .
- The ability to set an AWT uncaught exception handler using the -Dsun.awt.exception.handler property has been removed from Java 7.
http://www.devx.com/Java/Article/47634
Project Coin: "Small" Java 7 Tweaks, Big Dev Gains (Page last updated December 2011, Added 2011-12-28, Author S. Sangeetha, KL Nitin, Publisher devX). Tips:
- Strings are now usable as cases in switch statements from Java 7 (the implementation is efficient, but string comparison will always depend on the length and similarity of strings, so won't ever be as efficient as using numbers in the case statements)
- From Java 7 generic types don't need to be defined in the 'new' statement if the assigned-to variable defines the generic types (no performance implication, but code is simpler which is always good).
- Exception handling syntax has extended in Java 7 to allow:
catch(final Exception e)
allows subclass exceptions to be rethrown generically without redefining the method to throw the generic superclass exception (no performance implications); catch(Exception1 e1 | Exception2 e2 ... )
for multiple exception types using the same catch block (no performance implications); try(Closeable c = new ...()){...
where c is automatically closed when the try block is exited (this provides improved resource management, the vast majority of applications have slow resource leaks from resources not correctly closed).
http://www.ibm.com/developerworks/websphere/techjournal/1112_col_polozoff/1112_col_polozoff.html
Extending the benefits of proactive monitoring
(Page last updated December 2011, Added 2011-12-28, Author Alexandre Polozoff, Publisher IBM). Tips:
- Choosing monitoring granularity (the interval between samples) is a balance between too much data and finding out about problems later than ideal.
- When an application can no longer write to its logs the entire application hangs - so at least you should be monitoring disk space.
- If log space is shared, when the disk gets full all applications writing to that shared space could hang.
- Problems should be recorded in an operations log including details that describe the problem, what components participated, what people were involved in determining the problem, and what corrective actions were taken. The problem log should be reviewed and actions taken to prevent the problems recurring.
- Your test environment should have the same montoring tools as the production system so that monitoring capabilities and effects and reactions can be tested.
http://docs.oracle.com/javase/tutorial/essential/io/fileio.html
File I/O (Featuring NIO.2) (Page last updated November 2011, Added 2011-12-28, Author Oracle, Publisher Oracle). Tips:
- Java 7 Path objects now know about volumes and symbolic links, and is able to understand the relationships between paths and path components.
- The try-with-resources Statement allows Closeable resources to be automatically (and correctly) closed after the try block is exited.
- FileSystemException is specialized to support extra file information for better exception handling
- java.nio.file.Files supports several atomic file operations (e.g. move) where either the entire operation is performed or the operation fails.
- java.nio.file.Files supports globbing, file metadata, directory and file operations.
- java.nio.file.Path provides syntactic operations on it's paths, while java.nio.file.Files provides file system operations allowing you to separate IO and non-IO operations.
- StandardOpenOptions include options that allow delete-on-close, sparse files, and keeping the contents automatically synced with the underlying storage device.
- java.nio.file package provides a scalable asynchronous file change notification API, called the Watch Service API
which notifies on any of file creation, file deletion, or file modification
(note, if a file system does not support this mechanism, the Watch Service will poll the file system, waiting for events)
http://blog.dynatrace.com/2011/12/15/the-top-java-memory-problems-part-2/
The Top Java Memory Problems ? Part 2 (Page last updated December 2011, Added 2011-12-28, Author Michael Kopp, Publisher dynaTrace). Tips:
- It is possible to use multiple gigabytes of memory but this can lead to very long GC pauses.
- As a webserver can have many users, you can have quite a lot of active sessions, so it is important to keep the HTTP session cache small.
- HTTP session cache is not immediately released when the session is serviced, instead it is timed-out. This can easily cause excessive memory use.
- Memory-insensitive caches can cause excessive use of memory.
- Caches using soft references are popular, but often sft references are only released for critical memory conditions, which means that they can make critical memory conditions occur (since nothing is done to release memory until that condition is reached)
.
- Caches should be instrumented and properly monitored to ensure they do not cause a memory problem.
- If too many objects are created quickly, you get an increased number of GCs in the young generation. Young generation GCs are only cheap if most objects die; if a lot of objects survive the GC it can be more expensive than the equivalent old generation GC would be.
- Use the "dump heap on out of memory error" option so that you can determine the cause of OutOfMemoryErrors.
- A pathological scenario seen in many production systems is: multiple concurrent requests need enough memory to max the heap and cause OutOfMemoryError to occur for some of the requests; The subset of requests encountering OutOfMemoryError are aborted (typically by thread death) causing the memory they were using to be released; since memory is again available, the system doesn't look like it has had maxxed out memory unless you happen to look at just the right moment (or GC stats are being logged).
- Very large documents (PDF, XML, ...) can easily lead to very bad memory conditions, especially if the document processing is memory-inefficient, e.g. creates many very large temporary objects.
- Having multiple instances or versions of the same class in memory can cause bad memory issues. Monitor classesloaded to identify this.
- Incorrect implementations of equal and hashcode so that the correct relationship and mutability fails to hold can easily lead to leaks in hash-based data structures when objects with those incorrectly implemented methods are stored. Use code analysis and unit test tools to ensure the correct contract is present.
http://www.tomcatexpert.com/blog/2011/11/16/setting-measurement-garbage-collection-apache-tomcat
Setting Up Measurement of Garbage Collection in Apache Tomcat (Page last updated November 2011, Added 2011-12-28, Author Daniel Mikusa, Publisher tomcatexpert). Tips:
- Excessive garbage collection from badly tuned JVM parameters is a common cause for bad tomcat performance.
- Measure the performance before you make a change, make one change and then measure the performance after you have made the change. If you follow this pattern, you will always know exactly how the change you made affects the performance.
- Run a load generating tool like JMeter or Selenium on web applications.
- To measure tomcat garbage collection, add the following JVM options to the CATALINA_OPTS variable in the bin/ setenv.sh|bat file for your Tomcat instance.: -Xloggc:$CATALINA_HOME/logs/gc.log or Xloggc:%CATALINA_HOME%/logs/gc.log; -XX:+PrintHeapAtGC; -XX:+PrintGCDetails; -XX:+PrintGCTimeStamps; -XX:-HeapDumpOnOutOfMemoryError
http://www.tomcatexpert.com/blog/2011/11/22/performance-tuning-jvm-running-tomcat
Performance Tuning the JVM for Running Apache Tomcat (Page last updated November 2011, Added 2011-12-28, Author Daniel Mikusa, Publisher tomcatexpert). Tips:
- Use -Xms and -Xmx to specify the values of the heap.
- Use -XX:PermSize and -XX:MaxPermSize to set the size of the Perm Gen.
- If Perm Gen gets full, the JVM will run a full GC - applications which dynamically create or load a large number of classes could repeatedly get full GCs from having a badly configured Perm Gen size.
- Use -Xss to set the thread stack size - a typical installation can lower this to 128k and thus save memory for other parts of the system.
- Use the -server option to get the best performance.
- The JVM ships with three commonly used collectors: the serial collector, the parallel collector and the concurrent collector. The parallel collector -XX:+UseParallelGC typically offers the better throughput, while the concurrent collector -XX:+UseConcMarkSweepGC often offers lower pause times.
- To enable parallel compaction of the old generation space you can enable the option -XX:+UseParallelOldGC.
Jack Shirazi
Back to newsletter 133 contents
Last Updated: 2024-12-27
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/newtips133.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us