In simplest form, following is the design:
class Session {
Timer t = new Timer();
// ...
};
Whenever, Session
is allocated, I start a timer inside it; the timer will be expired after 10-20 mins. Now, suppose if Session
is destroyed before the timer can expire; then it's a scenario where I must stop timer. I don't know if is there any last method which is always called when Session
is destroyed.
Is there some sort of C++ destructor equivalent in Java, which help me to cancel()
the timer when Session
is destroyed ? (without waiting for GC)
Edit: Please don't retag for C++. I wanted something of that equivalent. The Session
is a phone session which is get destroyed when all the user connected to it are disconnected. Now, there is no Session
method which is called lastly nor there is any exception.