Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gardnervickers/ba8889c55c4600c629e7965f12cc2d36 to your computer and use it in GitHub Desktop.
Save gardnervickers/ba8889c55c4600c629e7965f12cc2d36 to your computer and use it in GitHub Desktop.
@Test
void testSignal() throws InterruptedException, IOException {
AtomicReference<Thread> threadRef = new AtomicReference<>();
Thread thread = new Thread(() -> {
Signal.handle(new Signal("USR2"), new SignalHandler() {
@Override
public void handle(Signal sig) {
System.out.println("Received signal: " + sig.getName());
var stackTrace = threadRef.get().getStackTrace();
for (var el : stackTrace) {
System.out.println(el);
}
// Implement your signal handling logic here
}
});
while (true) {
System.out.println("waiting");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
threadRef.set(thread);
thread.start();
Thread.sleep(1000);
System.out.println("sending signal");
Signal.raise(new Signal("USR2"));
System.out.println("sent signal");
Thread.sleep(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment