It isn't possible. A Session in HTTP is simply a bookmark that the server sends to the client so that on the next request the same application context will be used. Either side can discard this bookmark and the session is effectively ended, although in practice when a J(2)EE server invalidates a session, it also releases the session objects for potential garbage collection.
HTTP isn't a protocol that relies on a continuous communication like client/server does. It's strictly request/response and effectively each request/response transaction stands by itself, which is why the "bookmark" concept was developed to maintain the illusion of a formal connect/converse/disconnect mode of operation. Since the actual connect/disconnect occurs once per request, there's no way for the server to be notified that the browser is no longer communicating. If the browser wants to do another request, that's fine, but if the browse never submits another request again, that's also fine.
Because of this,
J2EE supports the idea that HttpSession objects have a countdown timer whose duration is defined in the web.xml file. If no requests are made within the countdown interval, the server will consider that as an indication that the user has gone away and discard the HttpSession. To force logout, you invoke the session.invalidate() method.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.