-
Notifications
You must be signed in to change notification settings - Fork 54.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAEL-5957: Creaet prime number finder for Kubernetes heap dump (#13190)
* 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
1 parent
6a0ffbb
commit 865833e
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
8 changes: 8 additions & 0 deletions
8
kubernetes-modules/k8s-java-heap-dump/src/k8s/prime-deploy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
...k8s-java-heap-dump/src/main/java/com/baeldung/kubernetes/heap/dump/PrimeNumberFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters