Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public class Common {
// for the sake of this example it avoids boilerplate ton inject an ejb into a spring context
public static final AtomicBoolean ENABLED = new AtomicBoolean(false);
public static final AtomicBoolean TRACE_REQUEST_PENDING = new AtomicBoolean(false);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.ejb;

import static com.example.Common.ENABLED;
import static com.example.Common.TRACE_REQUEST_PENDING;

import datadog.trace.api.Trace;
import javax.ejb.Schedule;
Expand All @@ -11,7 +11,7 @@ public class ScheduledEjb {

@Schedule(second = "*/1", minute = "*", hour = "*")
public void runIt() {
if (ENABLED.getAndSet(false)) {
if (TRACE_REQUEST_PENDING.getAndSet(false)) {
generateSomeTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.hello;

import static com.example.Common.ENABLED;
import static com.example.Common.TRACE_REQUEST_PENDING;

import java.util.concurrent.CompletableFuture;
import org.springframework.http.ResponseEntity;
Expand All @@ -17,10 +17,11 @@ public String hello() {

@RequestMapping("/enableScheduling")
public CompletableFuture<ResponseEntity<Void>> enableScheduling() {
ENABLED.set(true);
TRACE_REQUEST_PENDING.set(true);
return CompletableFuture.supplyAsync(
() -> {
while (!ENABLED.get()) {
// Wait until the scheduled task picks up the request.
while (TRACE_REQUEST_PENDING.get()) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
Expand Down