Results 1 to 8 of 8
- 08-13-2012, 09:15 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 32
- Rep Power
- 0
Java timer issue not running correctly
Hello,
Just looking for some help here.
I have created a separate timer class that runs once every 60 minutes. This class works fine.
Java Code:public Initialize(int seconds){ Timer timer = new Timer(); timer.schedule(new timerTask(), 0, 1*600000); } class timerTask extends TimerTask{ public void run(){ Date date = new Date(); try{ System.out.println(date); }catch (Exception e) { System.out.println(e); running = false; //stopping the execution of the thread if their is an error System.exit(0); while (running = false){ System.out.println("in the while command"); //after killing the thread I now need to restart the timer process thread automatically. //setting it to restart after 10 minutes Timer timer = new Timer(); timer.schedule(new timerTask(),600000); } } running=true; } } public static void main(String[] args) { new Initialize(0);
If I update the above code and add the code to implement a new class as per below...it seems to keep looping through the constructor, wont go into the main and wont come out of the constructor.
It also seems to loose the option to do it only once every 10 minutes.
I need to get it to run through the start element() end element to parse the data.Java Code:public void run(){ Date date = new Date(); try{ running=true; System.out.println(date); north = new north();
Any adviceLast edited by alexandra12; 08-13-2012 at 09:18 PM.
- 08-14-2012, 04:48 PM #2
Re: Java timer issue not running correctly
Should bewhile (running = false){
Java Code:while (running == false){
- 08-14-2012, 06:31 PM #3
- 08-14-2012, 07:40 PM #4
Re: Java timer issue not running correctly
Oops, I posted faster than I read :PNo, it should be
Java Code:
1
while (!running) {
- 08-14-2012, 09:43 PM #5
- 08-15-2012, 09:38 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Java timer issue not running correctly
You get problems like the above, where the assignment is valid in the statement as it produces a boolean result...so the simple rule is don't do it that way and you'll not end up with silly mistakes like that.
Please do not ask for code as refusal often offends.
- 08-15-2012, 01:52 PM #7
Re: Java timer issue not running correctly
Technically OT, but it's certainly bad form to name a variable running and then continue around a while loop while the value of that variable is false.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-16-2012, 10:47 PM #8
Member
- Join Date
- Jul 2011
- Posts
- 32
- Rep Power
- 0
Similar Threads
-
Timer Class Issue
By CuppaCoffee in forum New To JavaReplies: 3Last Post: 01-05-2012, 10:31 PM -
Need help with Timer running in background
By Azure in forum New To JavaReplies: 2Last Post: 05-22-2010, 02:08 PM -
Java Game Timer Issue! Help
By smithywill in forum Advanced JavaReplies: 2Last Post: 03-11-2010, 09:09 AM -
[SOLVED] Swing Timer issue
By Doctor Cactus in forum New To JavaReplies: 6Last Post: 03-03-2009, 12:25 PM -
Running Timer
By Doctor Cactus in forum New To JavaReplies: 2Last Post: 12-26-2008, 09:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks