Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Beginning Java
TIMER CLASS
sparsh khandelwal
Ranch Hand
Posts: 76
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
HELLO EVERYONE
import java.util.Timer; import java.util.TimerTask; import java.util.Scanner; public class ToDo1 { Timer timer; public ToDo1 ( int seconds ) { timer = new Timer ( ) ; timer.schedule ( new ToDoTask ( ) , seconds*1000 ) ; } class ToDoTask extends TimerTask { public void run ( ) { System.exit(0); System.out.println ( "\nOK, It's time to do something!" ) ; timer.cancel ( ) ; //Terminate the thread } } public static void main ( String args [ ] ) { System.out.println ( "Schedule something to do in 5 seconds." ) ; new ToDo ( 5 ) ; System.out.println ( "enter your input" ) ; Scanner mys=new Scanner(System.in); int i=mys.nextInt(); } }
while learning about timer class,i found this code(without System.exit(0)) on net.on adding System.exit(0); in the given code,come to know that exit() not working properly;
please help me to make it understand
thanks in advance
Campbell Ritchie
Marshal
Posts: 80747
486
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Where did you find that code
? What do you mean by
"not working properly"
? What did you expect to happen? Please edit your post to remove the
upper-case writing
.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Threads doubt
allocate time for a command
Create a counter that increments once a second until a given number of seconds is reached
stopping Timer after certain number of actions
Set Timer
More...