Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36665
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: timer task(s) with parameters |
| Date | 2017-05-30 07:57 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <ogjmg5$49b$1@dont-email.me> (permalink) |
| References | <ogjle5$1fq$1@gioia.aioe.org> |
On 5/30/2017 7:35 AM, newsgroups wrote:
> I want to schedule a timer task twice:
> once at currentime+15 secs with parameter="first" (and then every 22
> secs, but that's irrelevant)
> then at currentime+15+15 secs with parameter="second".
> Unfortunately, all the scheduled task run with parameter="second"
> :-(
> What am I doing wrong ?
> [...]
>
> public class SchedulaAllarme extends TimerTask {
> private static String messageToShow;
Because messageToShow is `static', it belongs to the entire
class as a whole. There is only one messageToShow, no matter how
many SchedulaaAllarme objects you create; they all share the same
messageToShow value. So ...
> SchedulaAllarme(String dataToShow) {
> this.messageToShow = dataToShow;
... the first time this constructor runs, it sets the shared
messageToShow to the dataToShow value. And the second time the
constructor runs, it changes the shared messageToShow to *its*
dataToShow value.
To give every SchedulaAllarme object its own unique messageToShow,
remove `static' from the declaration.
(Note: I have not examined the rest of your code carefully;
there might be other problems, too.)
--
esosman@comcast-dot-net.invalid
Thirteen hundred thirty-one days to go.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
timer task(s) with parameters newsgroups <pippo.pluto@disney.com> - 2017-05-30 13:35 +0200
Re: timer task(s) with parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-05-30 07:57 -0400
Re: timer task(s) with parameters newsgroups <pippo.pluto@disney.com> - 2017-05-30 14:05 +0200
Re: timer task(s) with parameters Robert Klemme <shortcutter@googlemail.com> - 2017-05-31 07:50 +0200
csiph-web