| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6215dce commit 7dab469
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,8 +48,9 @@ | |||
| 48 | 48 | <module>hotmethods</module> | |
| 49 | 49 | <module>latencies</module> | |
| 50 | 50 | <module>allocations</module> | |
| 51 | - <module>memoryleak</module> | ||
| 52 | 51 | <module>deadlock</module> | |
| 52 | + <module>memoryleak</module> | ||
| 53 | + <module>threadleak</module> | ||
| 53 | 54 | </modules> | |
| 54 | 55 | ||
| 55 | 56 | <dependencyManagement> | |
@@ -64,6 +65,11 @@ | |||
| 64 | 65 | <artifactId>base</artifactId> | |
| 65 | 66 | <version>${samples.version}</version> | |
| 66 | 67 | </dependency> | |
| 68 | + <dependency> | ||
| 69 | + <groupId>org.hdrhistogram</groupId> | ||
| 70 | + <artifactId>HdrHistogram</artifactId> | ||
| 71 | + <version>${hdrhistogram.version}</version> | ||
| 72 | + </dependency> | ||
| 67 | 73 | </dependencies> | |
| 68 | 74 | </dependencyManagement> | |
| 69 | 75 | ||
@@ -144,5 +150,6 @@ | |||
| 144 | 150 | <javac.target>1.8</javac.target> | |
| 145 | 151 | <samples.version>0.0.2-SNAPSHOT</samples.version> | |
| 146 | 152 | <jcommander.version>1.72</jcommander.version> | |
| 153 | + <hdrhistogram.version>2.1.10</hdrhistogram.version> | ||
| 147 | 154 | </properties> | |
| 148 | 155 | </project> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + Sample to show thread leaks in a Java Application | ||
| 2 | + ================================================= | ||
| 3 | + | ||
| 4 | + This sample application implements merge sort algorithm using multiple threads. | ||
| 5 | + | ||
| 6 | + The algorithm for parallel merge sort was taken from the [Merge Sort example available online from the University | ||
| 7 | + of Washington](https://courses.cs.washington.edu/courses/cse373/13wi/lectures/03-13/MergeSort.java) | ||
| 8 | + | ||
| 9 | + The original example uses threads directly. This sample application uses an `ExecutorService` to run threads. | ||
| 10 | + | ||
| 11 | + This application runs continuously and prints an interval summary statistics of algorithm run time for multiple random | ||
| 12 | + number arrays. The application will also print final summary statistics of algorithm run time at the program exit. | ||
| 13 | + | ||
| 14 | + ### How to run | ||
| 15 | + | ||
| 16 | + The application will throw Out of Memory error after some time when you run following command | ||
| 17 | + | ||
| 18 | + `java -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints | ||
| 19 | + -XX:+UnlockCommercialFeatures -XX:+FlightRecorder | ||
| 20 | + -XX:StartFlightRecording=settings=profile,duration=2m,name=ThreadLeak,filename=threadleak.jfr | ||
| 21 | + -XX:FlightRecorderOptions=loglevel=info | ||
| 22 | + -jar target/threadleak.jar` | ||
| 23 | + | ||
| 24 | + ### Analyzing Java Flight Recording | ||
| 25 | + | ||
| 26 | + In Threads -> Overview tab, you should see thread count is increasing steadily. | ||
| 27 | + | ||
| 28 | + ### How to fix the Thread Leak | ||
| 29 | + | ||
| 30 | + Run the application with `--stop-leakage` parameter, which will use a single `ExecutorService` throughout the | ||
| 31 | + application. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,51 @@ | |||
| 1 | + <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | + <!-- | ||
| 3 | + # Copyright 2018 M. Isuru Tharanga Chrishantha Perera | ||
| 4 | + # | ||
| 5 | + # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + # you may not use this file except in compliance with the License. | ||
| 7 | + # You may obtain a copy of the License at | ||
| 8 | + # | ||
| 9 | + # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + # | ||
| 11 | + # Unless required by applicable law or agreed to in writing, software | ||
| 12 | + # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + # See the License for the specific language governing permissions and | ||
| 15 | + # limitations under the License. | ||
| 16 | + --> | ||
| 17 | + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 18 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 19 | + | ||
| 20 | + <parent> | ||
| 21 | + <groupId>com.github.chrishantha.sample</groupId> | ||
| 22 | + <artifactId>java-samples</artifactId> | ||
| 23 | + <version>0.0.2-SNAPSHOT</version> | ||
| 24 | + <relativePath>../pom.xml</relativePath> | ||
| 25 | + </parent> | ||
| 26 | + | ||
| 27 | + <modelVersion>4.0.0</modelVersion> | ||
| 28 | + <artifactId>threadleak</artifactId> | ||
| 29 | + <packaging>jar</packaging> | ||
| 30 | + <name>threadleak</name> | ||
| 31 | + | ||
| 32 | + <dependencies> | ||
| 33 | + <dependency> | ||
| 34 | + <groupId>com.github.chrishantha.sample</groupId> | ||
| 35 | + <artifactId>base</artifactId> | ||
| 36 | + </dependency> | ||
| 37 | + <dependency> | ||
| 38 | + <groupId>org.hdrhistogram</groupId> | ||
| 39 | + <artifactId>HdrHistogram</artifactId> | ||
| 40 | + </dependency> | ||
| 41 | + </dependencies> | ||
| 42 | + | ||
| 43 | + <build> | ||
| 44 | + <plugins> | ||
| 45 | + <plugin> | ||
| 46 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 47 | + <artifactId>maven-shade-plugin</artifactId> | ||
| 48 | + </plugin> | ||
| 49 | + </plugins> | ||
| 50 | + </build> | ||
| 51 | + </project> | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments