Created
April 6, 2024 01:05
-
-
Save gardnervickers/ba8889c55c4600c629e7965f12cc2d36 to your computer and use it in GitHub Desktop.
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
@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