Yes it is possible, Create a class that implements javax.servlet.http.HttpSessionListener and annotate it with @WebListener which gives you access to method sessionCreated and sessionDestroyed.
Sample Code -
@WebListener
public class UserSessionListener implements HttpSessionListener {
@Override
public void sessionCreated(HttpSessionEvent arg0) {
System.out.println("Session Created");
}
@Override
public void sessionDestroyed(HttpSessionEvent arg0) {
System.out.println("Session Destroyed");
}
}
That is all you have to do.