I am registering an event handler with the evenadmin.
pingRegistration = bc.registerService(
EventHandler.class.getName(), new PingEventHandler(), p);
private class PingEventHandler implements EventHandler {
@Override
public synchronized void handleEvent(Event event) {
String userId = "";
for (String name : event.getPropertyNames()) {
if (name.equals("type")) {
if
(event.getProperty(name).equals(PingDTO.class.getCanonicalName())) {
userId = (String)event.getProperty("userId");
}
}
}
if (!userId.isEmpty()) {
IUser pingedUser = UserManager.this.getUser(userId);
pingedUser.setLastActive(LocalDateTime.now());
pingedUser.getId().ifPresent(id -> {
UserManager.this.put(pingedUser);
});
}
}
}
Things seem to run through all the code ok but after each ping event a new
thread is created for the EventHandler and it never gets destroyed but only
parked. Because of that my program quickly uses up all the cpu on the
box. Is there a way to have the Executer that runs the eventHandles clear
the thread when it is done or am I doing something wrong and have a loop
that I am just missing.
Thanks for any help,
David