473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

i don' understand why my Alarm is blocked

Hi
I have developed an Alarm, I haven' problem of runtime or compiletime but the application seems blocked.
When I call the method AlarmExecute, it runs only the first time ( when i click onto run button of Eclipse), I seen only one time the hour in the console!
please could anyone help me.
This the code

[PHP]import java.util.Timer ;

public class Alarm {
private int s;
private int h;
private int m;
private int[]timeNow;
private Timer timer;
private AlarmTask almTsk;

public Alarm (int hour, int min) { //hour, min ->alarm time set by the user
h=hour;
m=min;
s=60;
timer=new Timer();
almTsk=new AlarmTask();
timeNow=new int[2];
}
public void AlarmExecute(){
try{
timer.scheduleAtFixedRate(almTsk, 0, s*1000); //sample at 30s
timeNow=almTsk.TimeNow();
System.out.print(timeNow[0]);
System.out.print(timeNow[1]);
if(timeNow[0]==h && timeNow[1]==m){
System.out.print("Alarm");
StopAlarm();
}
}
catch (IllegalArgumentException e1){
System.out.println("delay is negative");
}
catch (IllegalStateException e2){
System.out.println("task was already scheduled or cancelled, timer was cancelled");
}
}
public void StopAlarm (){
timer.cancel();
}

}


import java.util.Calendar;
import java.util.TimerTask;

public class AlarmTask extends TimerTask{
private int[] timeNow;
private Calendar cal;

public AlarmTask(){
timeNow=new int[2];
cal=Calendar.getInstance();
//System.out.print(cal.get(Calendar.HOUR_OF_DAY));
}

public void run(){ //sample of time
timeNow[0]=getHour();
timeNow[1]=getMinute();
}
public int getHour(){
return cal.get(Calendar.HOUR_OF_DAY);

}
public int getMinute(){
return cal.get(Calendar.MINUTE);
}

public int[]TimeNow(){
return timeNow;
}


}

ublic class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Alarm a;
a=new Alarm(23,20);
a.AlarmExecute();

}

}

[/PHP]
Apr 2 '07 #1
0 1176

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

Similar topics

8
by: Bill H | last post by:
I have a typical username/password check against mysql type logon that Zone Alarm Pro seem to break... I haven't bought or troubleshooted this yet, I'm hoping this is a know issue with a simple...
0
by: Ishwar Rattan | last post by:
System is Mandrale 9.1 Linux with Pyhton-2.2.3 I want to abort the stdin-read operation if no input is avalable. Is it possible to achieve this? Sample code is given below. -ishwar ---...
4
by: Jeff Stewart | last post by:
Specifically, I don't understand the parameter that Synclock accepts. How is a reference type a lockable entity? What -is- a reference type? Is it a number? Is it a value at a specific memory...
1
by: Sergey | last post by:
How to send alarm to a thread? I can set alarm in main thread, but how then send exception to another thread to wake it if it executes too long?
7
by: Adrian Casey | last post by:
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is...
3
by: ankitks | last post by:
Hi guys, is there any utility available as a protection against endless_loop() something like this: alarm.set(5); //set timeout for 5 sec endless_loop(); alarm.reset(); //reset it to 0,...
0
by: thelightkeeper | last post by:
Hi, in MSSQL, I have 2 tables naming , --------------------------------------- EquipmentID : nvarchar(50), FK, reference .EquipmentID AlarmID : nvarchar(50), PK AlarmHappenTime :...
2
by: Alan Isaac | last post by:
Goal: turn off an audible alarm without terminating the program. For example, suppose a console program is running:: while True: sys.stdout.write('\a') sys.stdout.flush() time.sleep(0.5) ...
8
by: superleochen | last post by:
Database is simliar to this: ID TIME TAGNAME VALUE 5967383 8/1/2008 1:00:24 AM I16MUDL11 ALARM 5967384 8/1/2008...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.