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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
TIMER CLASS
sparsh khandelwal
Ranch Hand
Posts: 76
posted 13 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: 79153
377
posted 13 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
.
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...