System get hang/freeze when i use util or swing Timer. How can i get ride of this?
Other user interface i am calling this Task as below, after retrying, the whole system get frozen.
TimerTask t = new Task("Local",a);
java.util.Timer timer = new java.util.Timer();
timer.scheduleAtFixedRate(t, 0, 10000);
Try 3: FAIL
import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
public final class Task extends TimerTask {
private static Timer timer;
//private static ui.V v;
private static int input;
private static String sinput;
public static void main (String... arguments ) {
TimerTask f = new Task("Local:",20);
timer = new Timer();
timer.scheduleAtFixedRate(f, 0, 10000);
}
public Task(String sinput, int input) {
this.input = input;
this.sinput = sinput;
}
public void run() {
System.out.println("Will freeze, dont freeze.....");
//v = new ui.V(sinput); loading a user interface
//v.up(input); show the value
try {
Thread.sleep(4000); // wait 4 seconds
} catch (InterruptedException ex) {
Logger.getLogger(Task.class.getName()).log(Level.SEVERE, null, ex);
}
//v.killme(); // kill the display
timer.cancel();
}
}
I have also tried following method's but all same result system get freezed, and manually i have to power off and on the PC.
Try 0: FAIL
t = new java.util.Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
// same
}
}, 0, 10000);
Try 1: FAIL
t = new javax.swing.Timer(10000, new ActionListener() {
public void actionPerformed(ActionEvent ae) {
// same
}
});
t.start();
Try 2: FAIL
new Thread(new Runnable() {
public void run() {
t = new javax.swing.Timer(10000, new ActionListener() {
public void actionPerformed(ActionEvent ae) {
// same
}
});
t.start();
}
}).start();