Recently faced this question in an interview:
You have a java application, and it uses a connection object to connect to the different clients. The connection object is of type ClientConnection. I want to know how many live connection objects are present at a particular moment in this application?
Answer given by me:
- I will make a static variable connectionCount in ClientConnection class.
- Every time ClientConnection constructor is called, I will increment the static variable count by 1.
- I will override the finalize() method in ClientConnection and decrements the variable count by 1, every time it is called.
But Interviewer doesn't look satisfied by this answer.
Do we have any other approach for this question?
Aucun commentaire:
Enregistrer un commentaire