This repository was archived by the owner on Jul 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 9 files changed +219
-7
lines changed
src/main/java/com/example/springboot Expand file tree Collapse file tree 9 files changed +219
-7
lines changed Original file line number Diff line number Diff line change @@ -46,15 +46,24 @@ services:
4646 - 8082:8080
4747 networks :
4848 - phlare
49-
5049 java-simple :
5150 build :
5251 context : java/simple
5352 dockerfile : Dockerfile
5453 cap_add :
5554 - SYS_ADMIN
5655 ports :
57- - 8083:8080
56+ - 8083:4001
57+ networks :
58+ - phlare
59+ java-springboot :
60+ build :
61+ context : java/springboot
62+ dockerfile : Dockerfile
63+ cap_add :
64+ - SYS_ADMIN
65+ ports :
66+ - 8084:8080
5867 networks :
5968 - phlare
6069
Original file line number Diff line number Diff line change 1- FROM openjdk:11-jdk-slim
2-
3- RUN apt-get install libstdc++6
1+ FROM openjdk:11-slim-bullseye
42
53WORKDIR /app
64
75COPY . .
86
97RUN ./gradlew clean build
108
11- EXPOSE 8080
9+ EXPOSE 4001
1210
13- CMD ["./gradlew" ,"run" ]
11+ CMD ["./gradlew" , "run" ]
Original file line number Diff line number Diff line change 1+ package com .example ;
2+
3+ import java .net .InetSocketAddress ;
4+ import com .sun .net .httpserver .HttpServer ;
5+ import jpprof .PprofHttpHandler ;
6+
7+ public class Main {
8+
9+ public static void main (String [] args ) throws Exception {
10+ // run some background worload
11+ var t = new Thread (new Something ());
12+ t .start ();
13+
14+ var server = HttpServer .create (new InetSocketAddress (4001 ), 0 );
15+ server .createContext ("/" , new PprofHttpHandler ());
16+ server .start ();
17+ }
18+
19+ }
Original file line number Diff line number Diff line change 1+ package com .example ;
2+
3+ import java .io .File ;
4+ import java .io .FileWriter ;
5+
6+ public class Something extends Thread {
7+
8+ public Something () {
9+ super ();
10+ }
11+
12+ @ Override
13+ public void run () {
14+ doSomething ();
15+ }
16+
17+ private static void doSomething () {
18+ int i = 0 ;
19+ for (;;) {
20+ i ++;
21+ if (i % 3 == 0 ) {
22+ funcFoo ();
23+ }
24+ funcBar ();
25+ }
26+ }
27+
28+ private static void funcFoo () {
29+ funcBuzz ();
30+ }
31+
32+ private static void funcBar () {
33+ funcBaz ();
34+ }
35+
36+ private static void funcBaz () {
37+ try {
38+ File f = File .createTempFile ("foo" , "bar" );
39+ FileWriter w = new FileWriter (f );
40+ w .write ("hello" );
41+ w .close ();
42+ f .delete ();
43+ } catch (Exception e ) {
44+ e .printStackTrace ();
45+ }
46+
47+ }
48+
49+ private static void funcBuzz () {
50+ try {
51+ File .listRoots ();
52+ } catch (Exception e ) {
53+ e .printStackTrace ();
54+ }
55+ }
56+
57+ }
Original file line number Diff line number Diff line change 1+ FROM openjdk:11-slim-bullseye
2+
3+ WORKDIR /app
4+
5+ COPY . .
6+
7+ RUN ./gradlew clean build
8+
9+ EXPOSE 8080
10+
11+ CMD ["./gradlew" , "bootRun" ]
Original file line number Diff line number Diff line change 1+ package com .example .springboot ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .context .ApplicationContext ;
6+
7+ @ SpringBootApplication
8+ public class Application {
9+
10+ public static void main (String [] args ) {
11+ // run some background worload
12+ Thread t = new Thread (new Something ());
13+ t .start ();
14+
15+ ApplicationContext ctx = SpringApplication .run (Application .class , args );
16+ }
17+
18+ }
Original file line number Diff line number Diff line change 1+ package com .example .springboot ;
2+
3+ import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .RestController ;
5+
6+ @ RestController
7+ public class HelloController {
8+
9+ @ GetMapping ("/" )
10+ public String index () {
11+ return "Greetings from Spring Boot!" ;
12+ }
13+
14+ }
Original file line number Diff line number Diff line change 1+ package com .example .springboot ;
2+
3+ import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .RestController ;
5+ import org .springframework .web .bind .annotation .RequestParam ;
6+ import org .springframework .web .bind .annotation .ResponseBody ;
7+
8+ import javax .servlet .http .HttpServletResponse ;
9+ import java .io .IOException ;
10+ import java .time .Duration ;
11+
12+ import jpprof .CPUProfiler ;
13+
14+ @ RestController
15+ public class PprofController {
16+
17+ @ GetMapping ("/debug/pprof/profile" )
18+ @ ResponseBody
19+ public void profile (@ RequestParam (required = false ) String seconds , HttpServletResponse response ) {
20+ try {
21+ Duration d = Duration .ofSeconds (Integer .parseInt (seconds ));
22+ CPUProfiler .start (d , response .getOutputStream ());
23+ response .flushBuffer ();
24+ } catch (Exception e ) {
25+ System .out .println ("exception: " + e .getMessage ());
26+ }
27+ }
28+
29+ }
Original file line number Diff line number Diff line change 1+ package com .example .springboot ;
2+
3+ import java .io .File ;
4+ import java .io .FileWriter ;
5+
6+ public class Something extends Thread {
7+
8+ public Something () {
9+ super ();
10+ }
11+
12+ @ Override
13+ public void run () {
14+ doSomething ();
15+ }
16+
17+ private static void doSomething () {
18+ int i = 0 ;
19+ for (;;) {
20+ i ++;
21+ if (i % 3 == 0 ) {
22+ funcFoo ();
23+ }
24+ funcBar ();
25+ }
26+ }
27+
28+ private static void funcFoo () {
29+ funcBuzz ();
30+ }
31+
32+ private static void funcBar () {
33+ funcBaz ();
34+ }
35+
36+ private static void funcBaz () {
37+ try {
38+ File f = File .createTempFile ("foo" , "bar" );
39+ FileWriter w = new FileWriter (f );
40+ w .write ("hello" );
41+ w .close ();
42+ f .delete ();
43+ } catch (Exception e ) {
44+ e .printStackTrace ();
45+ }
46+
47+ }
48+
49+ private static void funcBuzz () {
50+ try {
51+ File .listRoots ();
52+ } catch (Exception e ) {
53+ e .printStackTrace ();
54+ }
55+ }
56+
57+ }
You can’t perform that action at this time.
0 commit comments