Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Outline

Sample to show latencies in a Java Flight Recording

This program has two threads: Even and Odd to print Even and Odd numbers.

Run the program and also make a profiling recording.

How to run

java -Xms64m -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=30s,name=Latencies,filename=latencies.jfr -Xlog:jfr=info -jar target/latencies.jar

Analyzing Java Flight Recording

In Threads -> Latencies tab, you should see that the program has many blocked events.

You should also see red blocks in Events -> Graph tab. Red blocks are not good as the thread is just waiting to acquire a lock.

See Threads -> Contention tab to see the Locks and also see Threads -> Lock Instances to check whether both threads share the same lock instances.

Improving Performance

Since there is no shared resource to protect, you can avoid the synchronized keyword and improve the performance.

Try the program again after removing the synchronized keyword in isEven method.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.