Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33311

Re: multithread client socket

Path csiph.com!news.swapon.de!aioe.org!.POSTED!not-for-mail
From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: multithread client socket
Date Sat, 5 Dec 2015 20:00:12 -0500
Organization Aioe.org NNTP Server
Lines 44
Message-ID <n401as$jaf$1@speranza.aioe.org> (permalink)
References <75df5111-41b9-4833-8497-69104f011d14@googlegroups.com>
NNTP-Posting-Host 1lM8B9/qdtKBc/uIRK2Gjw.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.java.programmer:33311

Show key headers only | View raw


On 12/1/2015 12:36 PM, Philipp Kraus wrote:
> I'm using a cached thread pool which gets a lot of callable objects.
> Each callable create with "new Socket" a client socket to a server,
> sends data to the server, receive the response and returns the
> response with a future object. The server closes the socket after the
> response is send.
>
> On large datasets the runtime cannot create new socket objects
> (socket already in use message). The Java client runs explicit
> socket.close without any error. My idea is, that each thread of the
> thread-pool holds a member with the socket, but I need must reconnect
> the client socket on each task, because the server closes the
> socket.
>
> My question is, how can I use a lot of client sockets which can be
> closed by the server, but without re instantiation on Java side. On a
> socket.connect I get "socket is closed" after the server has closed
> it.

Are you by any chance running your Java application on Windows?

I have had lots of problem with opening and closing a large number
of sockets on Windows.

It seems like:
* Windows keep the outbound port open for a short time after
   application close
* Windows has a rather strict limit on the number of outbound
   ports

The best approach would be avoid opening and closing
sockets all the time time and keep the sockets open
permanently and just put them in a pool for reuse.

That may not be possible due to the way the servers
works, but it should be considered.

The more hackish workaround is to bump MaxUserPort.

https://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx

http://smallvoid.com/article/winnt-tcpip-max-limit.html

Arne

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

multithread client socket Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-12-01 09:36 -0800
  Re: multithread client socket Eric Douglas <e.d.programmer@gmail.com> - 2015-12-01 11:58 -0800
    Re: multithread client socket Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-12-01 23:02 -0800
      Re: multithread client socket Eric Douglas <e.d.programmer@gmail.com> - 2015-12-02 06:39 -0800
  Re: multithread client socket Jan Burse <janburse@fastmail.fm> - 2015-12-01 22:01 +0100
    Re: multithread client socket Jan Burse <janburse@fastmail.fm> - 2015-12-01 22:06 +0100
      Re: multithread client socket Eric Douglas <e.d.programmer@gmail.com> - 2015-12-01 13:55 -0800
    Re: multithread client socket Martin Gregorie <martin@address-in-sig.invalid> - 2015-12-01 22:04 +0000
      Re: multithread client socket Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-12-01 23:04 -0800
        Re: multithread client socket Eric Douglas <e.d.programmer@gmail.com> - 2015-12-02 05:52 -0800
        Re: multithread client socket Martin Gregorie <martin@address-in-sig.invalid> - 2015-12-02 14:38 +0000
  Re: multithread client socket Arne Vajhøj <arne@vajhoej.dk> - 2015-12-05 20:00 -0500

csiph-web