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


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

Re: VERY PECULIAR PROBLEM

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 Robbie Brown <rob@example.com>
Newsgroups comp.lang.java.programmer
Subject Re: VERY PECULIAR PROBLEM
Date Thu, 12 Mar 2015 19:29:41 +0000
Organization A noiseless patient Spider
Lines 82
Message-ID <mdspdo$1pu$1@dont-email.me> (permalink)
References <f9da1c67-a91e-4ec6-8199-137af1736453@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Thu, 12 Mar 2015 19:28:56 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="6f44738199d8e778bc2b1b43708fc87f"; logging-data="1854"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2x6NyV/X1N3xMbd0Orb+p42cWzLRVQqc="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
In-Reply-To <f9da1c67-a91e-4ec6-8199-137af1736453@googlegroups.com>
Cancel-Lock sha1:ufDt2DgsqZUN0NdSbgldCpYCb0k=
Xref csiph.com comp.lang.java.programmer:31316

Show key headers only | View raw


On 12/03/15 18:38, 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?
>
>   public void run(){
>          long timeStamp = System.currentTimeMillis();
>
>          while(true){
>              if(timeStamp + 1000 <= System.currentTimeMillis()){
>                  timeStamp = System.currentTimeMillis();
>
>                  System.out.print("");
>                  if(this.paused==false){
>                      this.secCount++;
>
>                      this.hrs = (int)this.secCount / 3600;
>                      this.min = (int)(((int)(this.secCount % 3600))/60);
>                      this.sec = (int)this.secCount % 60;
>
>                      if(this.debug) System.out.println("Timer: "+this.hrs+":"+this.min+":"+this.sec);
>                  }
>              }
>          }
>      }
>
> Much thanks for any ideas, I have NO IDEA why a System.out.print statement could impact the functioning of this program to such an extent?
> Doug
>

Hmm, I just wrapped your code in a *simple* test class and ran it, it 
produces output with or without the System.out, I think you should be 
looking elsewhere.

package com.foo;

public class TimerTest extends Thread{
	
	int hrs, min, sec, secCount;
	boolean debug = true;
	boolean paused = false;
	
	public void run(){
         long timeStamp = System.currentTimeMillis();

         while(true){
             if(timeStamp + 1000 <= System.currentTimeMillis()){
                 timeStamp = System.currentTimeMillis();

                 //System.out.print("");
                 if(this.paused==false){
                     this.secCount++;

                     this.hrs = (int)this.secCount / 3600;
                     this.min = (int)(((int)(this.secCount % 3600))/60);
                     this.sec = (int)this.secCount % 60;

                     if(this.debug) System.out.println("Timer: 
"+this.hrs+":"+this.min+":"+this.sec);
                 }
             }
         }
     }
	
	public static void main(String[] args){
		new TimerTest().start();
	}

}

//output

Timer: 0:0:1
Timer: 0:0:2
Timer: 0:0:3
Timer: 0:0:4
Timer: 0:0:5
Timer: 0:0:6
Timer: 0:0:7
... etc


-- 
Not floundering ... just fishing

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


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