In my application there will be one thread which always be running and will be sending or listening to some port.
This application runs in the background. Sometimes while creating the socket, i found that the port which was used by the same thread before, is not getting released on close() of the socket. So i tried like this
dc = new DatagramSocket(inetAddr);
BindException: Address already in use
MulticastSocket. Construct it with no arguments. That implicitly calls setReuseAddress(true). Then call bind().
At the moment you are calling setReuseAddress() too late for it to do any good.