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


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

Re: "heartbeat" approach

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: "heartbeat" approach
Date Sat, 02 Feb 2013 00:13:04 +0100
Lines 44
Message-ID <an30g1Fe3dU1@mid.individual.net> (permalink)
References <0e900395-a38a-44a1-a5bf-01cc781c8728@googlegroups.com> <510c45ba$0$293$14726298@news.sunsite.dk>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding quoted-printable
X-Trace individual.net i7Z6JhIhE5IE8ycceR3fVwH4jDI70Row8yZgCm16Yz5RF/JQ+FfuKcP6Pztnb8aqc=
Cancel-Lock sha1:xSbalfnI6nADWChL2ZMPzIzieRw=
User-Agent Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
In-Reply-To <510c45ba$0$293$14726298@news.sunsite.dk>
Xref csiph.com comp.lang.java.programmer:21986

Show key headers only | View raw


On 01.02.2013 23:46, Arne Vajhøj wrote:
> On 2/1/2013 11:11 AM, bob smith wrote:
>> What is the best way to handle a situation where you want a socket to
>> send a "heartbeat" every ten minutes?  I was thinking it would be
>> simple to have a single thread do all the "heartbeat" sending.

http://docs.oracle.com/javase/6/docs/api/java/util/Timer.html

>> However, that means there could be multiple threads writing to one
>> socket.  Do I need to do anything special to have multiple threads
>> writing to one socket?  Is there a better way?
>
> You can certainly let the two writing thread synchronize on
> Socket or OutputStream objects to make it thread safe.

Yes, _some_ form of synchronization is needed.

> You could also funnel all writes through the same
> thread (a writer thread) via some in memory data structure
> (which you would then need to synchronize on).

The details of course depend on the nature of the heartbeat (e.g. can it 
be omitted if there was regular traffic in the meantime?  How much delay 
for the heartbeat is allowed etc.).

> The last option would end up as much more complex
> code from start, but I believe that the design may
> end up being preferable as the solution itself evolves.
> Consider how many places you nee to change if you want to
> switch from TCP to UDP.

We could certainly come up with better solutions if we had more 
information about the scenario.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

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


Thread

"heartbeat" approach bob smith <bob@coolfone.comze.com> - 2013-02-01 08:11 -0800
  Re: "heartbeat" approach Knute Johnson <nospam@knutejohnson.com> - 2013-02-01 08:40 -0800
  Re: "heartbeat" approach Arne Vajhøj <arne@vajhoej.dk> - 2013-02-01 17:46 -0500
    Re: "heartbeat" approach Robert Klemme <shortcutter@googlemail.com> - 2013-02-02 00:13 +0100
      Re: "heartbeat" approach Arne Vajhøj <arne@vajhoej.dk> - 2013-02-01 18:21 -0500
      Re: "heartbeat" approach Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-02-03 06:51 -0400
  Re: "heartbeat" approach Roedy Green <see_website@mindprod.com.invalid> - 2013-02-01 15:20 -0800

csiph-web