Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31317
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: VERY PECULIAR PROBLEM |
| Date | Thu, 12 Mar 2015 22:52:51 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 34 |
| Message-ID | <mdtmt9$3te$1@dont-email.me> (permalink) |
| References | <f9da1c67-a91e-4ec6-8199-137af1736453@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Fri, 13 Mar 2015 03:52:09 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="8cedddb29338592f734c41b16a68fadc"; logging-data="4014"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0UfvVP0ck8VRJuxTxBNHGq2o65tUiGXg=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Thunderbird/36.0 |
| In-Reply-To | <f9da1c67-a91e-4ec6-8199-137af1736453@googlegroups.com> |
| Cancel-Lock | sha1:T3W8HLFYR9wcTOpFeCAMEmWMcXw= |
| Xref | csiph.com comp.lang.java.programmer:31317 |
Show key headers only | View raw
On 3/12/2015 1:38 PM, Doug Mika wrote:
> Hi to all, I don't know what is wrong with the following method. It
> is a method inside a Timer class that extends Thread. The peculiar
> problem is that IF i include the System.out.print(""); line in the
> method, the program works FINE, if however I delete the
> System.out.print(""); methods or REM it out, the program doesn't
> count time? How Could that one line which does NOTHING cause the
> entire program to function correctly?
I don't know. Your test case contains insufficient details to let us do
anything else other than wildly guess at what your code is doing. For
all I know, it's supposed to be training a hyena to chew off your balls
and it's instead training it to chew off your nose.
More seriously though, despite the almost total lack of information, I'm
going to guess that the problem is that paused (and probably secCount
too, come to think of it) is not declared in the class to be a volatile
variable. That, or some sort of lack of synchronization (of which
volatile is a form of synchronization, but I digress), or possibly a
timing issue.
To answer your "how" question (which is still instructive even if my
guess is completely wrong), the JIT compiler is free to do whatever it
wants so long as it preserves observable behavior. In this case, the
compiler would see an infinite loop and variables that are written to
but never read. If the variables are not declared volatile, then there
is no guarantee that they will ever be read or written to if accessed
from multiple threads unless you provide some sort of synchronization. A
call to System.out.print very possibly could cause that sort of
synchronization, at least as far as the compiler knows.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
VERY PECULIAR PROBLEM Doug Mika <dougmmika@gmail.com> - 2015-03-12 11:38 -0700
Re: VERY PECULIAR PROBLEM Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-03-12 14:57 -0400
Re: VERY PECULIAR PROBLEM Robbie Brown <rob@example.com> - 2015-03-12 19:29 +0000
Re: VERY PECULIAR PROBLEM Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2015-03-12 22:52 -0500
Re: VERY PECULIAR PROBLEM Nigel Wade <nmw@ion.le.ac.uk> - 2015-03-13 09:36 +0000
Re: VERY PECULIAR PROBLEM Robbie Brown <rob@example.com> - 2015-03-13 10:12 +0000
Re: VERY PECULIAR PROBLEM Robert Klemme <shortcutter@googlemail.com> - 2015-03-13 21:40 +0100
csiph-web