Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8684251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:15:27+00:00 2026-06-12T22:15:27+00:00

I am coding a client/socket connection and I am using ThreadPools to handle several

  • 0

I am coding a client/socket connection and I am using ThreadPools to handle several clients.

After my Server has started I have several Resouces used. I want to close all of them if f.ex.: the server says to the client it should shutdown, I want to close everything.

I still coded a basic shutdown function:

public static void killClient() {
    try {
        threadpool.shutdown();
        in.close();//client input
        out.close();//client output
        socket.close();
    } catch(Exception e) {
        System.out.println("Client has been shutdown! " + e);
        e.printStackTrace();
    }
}

My question is:

How to be sure that everything has closed propely and nothing still runs anymore?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:15:28+00:00Added an answer on June 12, 2026 at 10:15 pm

    How to be sure that everything has closed propely and nothing still runs anymore?

    I’ve answered the specific question below.

    I think that it is more important to “close” your classes as opposed to concentrating on closing the resources. If a class (such as your Client class above) wraps resources such as a thread-pool and sockets, then it should have a close() method on it (such as your killClient() above). If the server forks a client then it should manage them so that a server.close() calls the various client.killClient() methods.

    If you get religious about properly shutting down the various classes, using try {} finally {} blocks everywhere, you should not have to worry about unclosed resources and hung threads.


    This is hard to do and there is no blanket answer for all resource types. Here’s a couple of ideas that might help.

    • For threads you can use something like Threads.getAllStackTraces() to show what threads are left. If you compare this list when your program starts and then when it finishes you should be able to see what’s left.

    • File descriptors are a lot harder. If you are running on Linux then you can look at the /proc/self/fd directory to see what descriptors are still open. Again compare start and end. You can also look at the OpenFileDescriptorCount JMX variable (java.lang:type=OperatingSystem) in your application but that just gives the number of descriptors without context.

    • There is no easy way to detect leaks in other resources. You could wrap a ResourceManager type class around them from which you “generate” and “release” a resource but this requires programming support. If you create a resource outside of the manager there is no easy way to detect the leak.

    • One example of a such a mechanism is what I do for ORMLite testing. ORMLite opens and closes a lot of database connections and I wanted to make sure I wasn’t bleeding them in my code. I created a wrapper around database connections that would register themselves with a manager when they were created and un-register themselves when they were closed. Then I could make sure that assertTrue(connectionManager.isAllConnectionsClosed());. Not sure if that’s helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm coding a simple websocket server on netty. Before a client connection has been
I am doing coding in linux architecture. I have question regarding socket server and
I have read a few good articles about coding a socket server but thought
I'm coding a client server pair in java and I would like the ports
I'm coding an application where the client app needs to authenticate with a server
I have two classes; one is a server, another one is a client, and
I have server and client to send/receive a string through windows sockets. Client code
I'm coding a simple TCP client/server in VB.NET to transfer files of all sizes.
I have the following Java socket client app, that sends same string to socket
I'm developing a simple network client/server. The client has a MainConnection class which maintains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.