473,503 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Timer

30 New Member
Hi ALL,

I want to print a message for every 5 seconds of the system time

How should i do it?

I 've written some code but loop is not correct ....

Waiting for sugestions ?

Please help ..

thanks
May 17 '07 #1
2 2209
r035198x
13,262 MVP
Hi ALL,

I want to print a message for every 5 seconds of the system time

How should i do it?

I 've written some code but loop is not correct ....

Waiting for sugestions ?

Please help ..

thanks
Let's see your code that's giving problems. Did you use the Thread.sleep method?
May 17 '07 #2
crossroadsk
30 New Member
Let's see your code that's giving problems. Did you use the Thread.sleep method?
Thanks for reply

solved the problem almost .... just need to control the loop because it is an continuous loop

Here is the code:
import java.io.*;
import java.util.*;
class TimerTest extends TimerTask
{
public static void main(String[] args) throws IOException
{
TimerTask tt = new TimerTest();
Timer t = new Timer();

/*while (new BufferedReader(new InputStreamReader(System.in)).read()!='x')
{
t.scheduleAtFixedRate(tt, new Date(),5000);
}*/
t.scheduleAtFixedRate(tt, new Date(),5000);
}
public void run()
{
System.out.println("Timer set for every 5 seconds");
}
}

remove the comments and comment the last line of main() to test the while loop.

Now i'll describe my actual task ...

we have to print documents according to the scheduled time.
That means,
if we select some files and set some time for that file, it should get printed without any manual interference. Setting time like once a day, once every 1 hour and so on....
May 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
12139
by: Gert Schumann | last post by:
I'm operating on sun OS 5.6 I ping a host every 10 seconds to get knowlegde wheather it is running or not. After about one and a half hour I get this Exception: java.io.IOException: Too many open...
47
5085
by: Theatre Mgmt | last post by:
Sun project seeks to solve Java memory, execution issues http://story.news.yahoo.com/news?tmpl=story&u=/infoworld/20050325/tc_infoworld/58059&e=1&ncid= San Francisco (InfoWorld) - Sun...
14
6526
by: mikeoley | last post by:
Why would this script below work on an html page: http://www.eg-designdev.com/aircylinders/test.htm But not a java page such as this: "http://www.eg-designdev.com/aircylinders/index3.jsp" Or...
13
1646
by: Paul | last post by:
Hi I have a .net application that shows the start page for a few seconds and then goes to another start page. I was wondering if it would be possible to put a count on the page to let the user...
26
3180
by: Christoph Zwerschke | last post by:
You will often hear that for reasons of fault minimization, you should use a programming language with strict typing: http://turing.une.edu.au/~comp284/Lectures/Lecture_18/lecture/node1.html I...
4
5414
by: puntino | last post by:
Hi I have created my Alarm, at compile time I don't have any problem, but at run time I receive the follo wing messages: Exception in thread "main" java.lang.NullPointerException at...
5
2282
by: IndependentDreams | last post by:
This is a java script code that will make it snow on your page. My problem is that it works just fine in IE and Opera, but doesn't work in Fire Fox or Safari. Here is the code. If you have any idea...
318
10735
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... ...
14
3009
by: Alexander Mahone | last post by:
Hello, I need a facility in C, like a set of functions, to manage a timer: I should be able to initialize it with a certain period of time (like x msec), start it, and every x msec it should...
0
7201
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.