Skip to content

Commit

Permalink
BAEL-5957: Creaet prime number finder for Kubernetes heap dump (#13190)
Browse files Browse the repository at this point in the history
* BAEL-5957: Creaet prime number finder for Kubernetes heap dump

* add dockerfile, kubernetes deploy file

* use baeldung namespace

* add saving primes to a list
  • Loading branch information
maciejglowka committed Mar 14, 2023
1 parent 6a0ffbb commit 865833e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kubernetes-modules/k8s-java-heap-dump/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM adoptopenjdk:11-jre-hotspot

ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
ENTRYPOINT ["java", "-jar", "application.jar"]
46 changes: 46 additions & 0 deletions kubernetes-modules/k8s-java-heap-dump/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>k8s-java-heap-dump</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>kubernetes-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<manifest>
<mainClass>com.baeldung.kubernetes.heap.dump.PrimeNumberFinder</mainClass>
</manifest>
</archive>
</configuration>

</plugin>
</plugins>
</build>

<properties>
<client-java.version>11.0.0</client-java.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: prime-number-finder-pod
spec:
containers:
- name: prime-number-finder
image: baeldung/prime-number:latest
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.baeldung.kubernetes.heap.dump;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

public class PrimeNumberFinder {
public static void main(String[] args) {
List<Integer> primes = new ArrayList<>();
int maxNumber = Integer.MAX_VALUE; // set to huge to make it run a long time

for (int i = 2; i < maxNumber; i++) {
if (isPrime(i)) {
System.out.println(i);
primes.add(i);
}
}
}

private static boolean isPrime(int number) {
return IntStream.rangeClosed(2, (int) (Math.sqrt(number)))
.allMatch(n -> number % n != 0);
}
}
1 change: 1 addition & 0 deletions kubernetes-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<module>k8s-intro</module>
<module>k8s-admission-controller</module>
<!-- <module>kubernetes-spring</module> --> <!-- JDK-11 Module -->
<module>k8s-java-heap-dump</module>
</modules>

</project>

0 comments on commit 865833e

Please sign in to comment.