File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Not sure if I'm closing a thread properly. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Not sure if I Watch "Not sure if I New topic

Not sure if I'm closing a thread properly.

joe vasher
Ranch Hand

Joined: Nov 06, 2009
Posts: 37
I wrote a server program that displays the id's of each thread as it opens. When I close a client connection it closes down properly. and it closes the socket. However next time I display the id's it has incremented by 1 in the server. Should the id if the thread was released properly re use the ID of the previous client??? also I noticed that I have about a 200 bit memory leak, per task manager. the server process keeps growing everytime I close a client by about 200 bytes?

I'm not calling anything like release thread (SHOULT I)?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

The way to terminate a thread is to return from the run() method.

You seem to have an expectation that the JVM will reuse numbers when it's assigning thread names. I'm not sure why you decided to expect that but no, it doesn't do that. It just does the simplest thing possible, which is to assign sequential numbers as thread names.
I agree. Here's the link:
subject: Not sure if I'm closing a thread properly.
It's not a secret anymore!