• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

a timing function in java

 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a java program which does a simple for loop
like this
class time{
public static void main(String args[])
{
for (int i = 0 ; i < 100 ; i++)
{
System.out.println(i);
}
}
}
but what i want to do is that i have a file (for ex value.txt)where i want to say something like this
[12.05.2002]
9:00
the day and time when this (above program) has to start ... how can i do it ???
any snippet will be helpful ...thanks in advance for ur support.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps java.util.Timer
 
vivek sivakumar
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Danke dirk!!!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun's Java Tutorial includes a lesson on Using the Timer and TimerTask Classes.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have one Timer Componet like this. load this componet in Servlet init method
*****************************************
import java.util.*;
import java.io.*;
public class SchedulerComponent
{
Date DateObj =new Date();
//load this text file value and set for date obj.
SchedulerComponent()
{
Timer objTimer = new Timer();
objTimer.scheduleAtFixedRate(new TimerTask()
{public void run()
{
for (int i = 0 ; i < 100 ; i++)
{
System.out.println(i);
}
//iCount1++;
}
}, 0, DateObj);
}
}
********************************************
I think this works for you..
Viswanatha GB
http://viswa.itgo.com
INDIA

Originally posted by vivek sivakumar:
i have a java program which does a simple for loop
like this
class time{
public static void main(String args[])
{
for (int i = 0 ; i < 100 ; i++)
{
System.out.println(i);
}
}
}
but what i want to do is that i have a file (for ex value.txt)where i want to say something like this
[12.05.2002]
9:00
the day and time when this (above program) has to start ... how can i do it ???
any snippet will be helpful ...thanks in advance for ur support.

 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic