GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sample-java-programs/threadleak at main · chrishantha/sample-java-programs

Expand file tree

/

threadleak

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

threadleak

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
src/main
src/main
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

README.md

Outline

Sample to show thread leaks in a Java Application

This sample application implements merge sort algorithm using multiple threads.

The algorithm for parallel merge sort was taken from the Merge Sort example available online from the University of Washington

The original example uses threads directly. This sample application uses an ExecutorService to run threads.

This application runs continuously and prints an interval summary statistics of algorithm run time for multiple random number arrays. The application will also print final summary statistics of algorithm run time at the program exit.

How to run

The application will throw Out of Memory error after some time when you run following command

java -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=2m,name=ThreadLeak,filename=threadleak.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/threadleak.jar

Analyzing Java Flight Recording

In Threads -> Overview tab, you should see thread count is increasing steadily.

How to fix the Thread Leak

Run the application with --stop-leakage parameter, which will use a single ExecutorService throughout the application.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.