We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


sockets and more.......

Buffon asked
Medium Priority
Last Modified: 2012-08-13
reference here: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_22024888.html

ok, I run thos lsof prog, and I got 350+ open file descriptors for my java process.....no good........
I see in there 100+ of those:

java    11917 root  452r  FIFO        0,5          39355157 pipe
java    11917 root  453r  FIFO        0,5          39274366 pipe
java    11917 root  454w  FIFO        0,5          39274366 pipe
java    11917 root  455w  FIFO        0,5          39355157 pipe
java    11917 root  456w  FIFO        0,5          39377724 pipe

and I have no idea what is it, I dont use pipes?!?

also there are a lot of those:
java    11917 root   14u  IPv6   38332031               TCP server.<mydomain.com>:22005->n220246244233.<clientdomain>.com:3159 (CLOSE_WAIT)

I do close the sockets but I see from this that it waits for close from client or something, but i waits too long, what I can do?

so practicaly its 2 questions there.
Watch Question

Can't you re-use sockets? I think you are opening lots of them is a short time.
Besides, not only close the sockets, but also null the references.



how can I reuse socket? and what is a short time for your opinion?


and I do null the reference by the way.
1000 sockets per seconds exists, but causes problems like these.
Reuse by keeping connections open and sending logical closes:
sending a certain packet to indicate change of use.
The problem you are experiencing has to do with the linger-time in the server. May be not easily configured.


1) its not even close to 1000 sockets per minute.
2) cannot reuse like this because client disconnects for real.
3) how can I configure linger time and what is it?
4) is it possible that pipes are from MySQL connections? Is it possible that MySQL connection library has a leak?
You are obvious running a flavour of UNIX or LINUX,
a FIFO is a pseudo file on disk, opened for write by an arbitrary process,
and written to a certain amount before it goes to sleep,
while an aother arbitrary process can read from this file, waking up sleeping writers,
but going to sleep itself when the file becomes empty.
I presume that you are using a network-simulation on disk.
In that case the simulation is rather bad in that the reader is not notified
when the writer disconnects from the FIFO.

1) I see
2) now I understand
3) in this case the problem is in the software you are using.
Linger time is the time that a connection is kept alive by a receiver before removing it.
But here it looks like the receiver is simply a FIFO reader and that goes on forever, unless someone deletes the FIFO.
4) Connections to MYSQL should be made to an application server that does direct database access.
The client(s) should connect to the server and not interfere with MYSQL directly (if they could).

Resume: I wonder what strange construct you are using that fakes connections via FIFO's.



1) ok, I will explain about my application. The statistics are from my application server, to which clients connect and it connects to database. There are a group of clients per thread in application server, I use Selector to go over all sockets. There is 1 connection per thread, and its persistent till the thread is close. The threads are closed, but probably cached by JVM because I use Executors.newFixedThreadPool. I explicitly close all the sockets and connection in the end of thread.
anything else to explain? :)

2) I use mysql-connector-java-3.1.10, may be it has the leak? should I use other driver? I know jdk 1.6 introduce JDBC 4.

3) any other possible reason?
That is beyond my knowledge.
My (conservative) feelings have make me avoid some 'new' developments
because they go quicker than they come.
In a server I would gladly create a thread per connection and release it at close.
And I would use one per client, fearing connections to remain somewhere, frustrating even the GC.
I've written very large applications with very many threads and I'm convinced that JAVA
is strong enough to not need pools for that purpose.



so what do you recommend me to do? Not to use thread pool? and what about linger time, how can I change it?
I still don't see where those FIFO's were created.
I don't know much about MYSQL, might it be an old version?



ok I will try newer version, but again what about linger time?
From the JAVADOC (if you don't have it, download it!):
Class Socket


public void setSoLinger(boolean on,
                        int linger)
                 throws SocketException

    Enable/disable SO_LINGER with the specified linger time in seconds. The maximum timeout value is platform specific. The setting only affects socket close.

        on - whether or not to linger on.
        linger - how long to linger for, if on is true.
        SocketException - if there is an error in the underlying protocol, such as a TCP error.
        IllegalArgumentException - if the linger value is negative.
    See Also:



:) sorry, of course I have it, I thought its some kind of Linux option. thanks. I will not close this question for now, may be someone else will know about pipes.
If the FIFO's remain with a newer server .... I rest my case.


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

DId you ever check how many active database connections are there?
Are you closing database connections explicitly ?
Is there any max_limit set on no of database connections opened from application server if you are using a connection pool mechanism?

And one thing. when client connects to your server when an each connection has one socket communication open
I am sure you will have one OutputStream open to write any data to cleint and one InputStream open to read data from cleint connected.
Are you closing these streams i.e Input and Output steams explicitly ?


1) I have one open connection to mysql opened in each thread, thread finishes, connection closed. no connection pooling.
2) I use nio, so no streams are involved, I interact with SocketChannel. sockets are also closed explicitly in the end of thread.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.