Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: timer task(s) with parameters Date: Wed, 31 May 2017 07:50:55 +0200 Lines: 29 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net W2KepKsoUKPEDtgTx2MMTQewIET6H9mJ+mw9511cuJZGBzN8g= Cancel-Lock: sha1:D7RJWeCO5FuyWHg+OrHAS3oX+EA= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:36667 On 30.05.2017 13:57, Eric Sosman wrote: > (Note: I have not examined the rest of your code carefully; > there might be other problems, too.) A few observations: For both recurring tasks one Timer instance is created. Normally the approach would be to just use one Timer instance - especially since tasks do not seem to be very heavy. Your use of variable declarations is very C-ish. Don't do that in Java. Rather declare them for the smallest necessary scope. This helps avoid one class of errors. format1 can be made final, as well as calendar and timer (when using one Timer only). Even for such a simple example you could factor out the common part of both scheduling activities and thus make it more readable. Getting into that habit will help you create more modular and less redundant code. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/