Class Loop {
MAIN {
FOR (start; 5 seconds; unlimited) {
System.out.println ("...");
IF (Press the Q key) {
Exit cycle
}
// No key or q key
Else {
Continue cycle
}
}
exit the program
}
}
-------------------------------------------------- -------------
Interval can be used
Java.util.Timer
ScheduleatFixedrate (Timertask Task, Long DELAY, Long Period)
As for how to receive Q, I will not say it.
-------------------------------------------------- -------------
The way upstairs is running in the thread.
OK
-------------------------------------------------- -------------
Below you should solve your problem :)
I want to see everyone's solution, can you say that the brothers upstairs can't say a little more?
Class ACCEPT
{
Public static void main (String [] args) {
Accept test = new accept ();
Test.go ();
}
Public void Go () {
Check Singlechk = New Check ();
SINGLECHK.START ();
Try {
While (! glope.quit_loop) {
System.out.Println ("Programm is Running ...");
Thread.sleep (5 * 1000);
IF (! glope.quit_loop) {
System.out.println ("Programm is doomething");
}
}
} catch (exception e) {
System.out.println (e);
}
GLOBLE.QUIT_THREAD = true; // Notification? Bunch
}
Import java.io. *;
Public class check extends thread {
InputStreamReader ISR = New InputStreamReader (System.in);
BufferedReader Br = New BufferedReader (ISR);
String ch = "";
Public synchronized void run () {
While (True &&! Global.quit_thread) {
Try {
CH = br.readline ();
System.out.println (".....");
IF (ch.equals ("q")) {
GLOBLE.QUIT_LOOP = TRUE
Break; // Exit Cycling;
}
} catch (exception e) {
System.out.println (e);
}
}
}
}
Public class glope {
Public static char Just_click = 0 ;;
Public static boolean quit_loop = false;
Public static boolean quit_thread = false;}
-------------------------------------------------- -------------
If you go upstairs, you don't read from System.in.
-------------------------------------------------- -------------
Import java.io. *;
Import java.util. *;
Public Class Threadtest Extends Thread
{
Public void run () {
For (;;) {
System.out.println (new java.util.date ()); // can be replaced with the task you want to perform.
Try {
SLEEP (5 * 1000);
} Catch (exception e) {
}
}
}
Public static void main (String [] args) {
CHAR EXIT = '';
Thread t = new threadtest ();
T.SETDAEMON (TRUE);
T.Start ();
While (exit! = 'q' && exit! = 'q') {
Try {
System.out.println ("PRESS Q / Q to EXIT:");
EXIT = (char) system.in.read ();
} Catch (ioexception e) {
}
}
System.out.println ("Process Finished.");
}
}