public void run() { while (thread != null) { if (((new Date()).getTime() - getStartDate().getTime()) >= 10000) { stop(); } listener.onEvent(new EventObject(this)); eventsSent++; try { Thread.sleep(250); } catch (InterruptedException e) { e.printStackTrace(); } } }
public void run() { try { while (isRunning()) { Thread.sleep(10000); Date current = new Date(System.currentTimeMillis()); if (messages.size() >= 10) { messages.remove(0); } messages.add(messages.size(), String.valueOf(counter++) + " at " + current.toString()); System.out.println("event occurs"); synchronized (listener) { listener.onEvent(new EventObject(this)); } } } catch (InterruptedException e) { e.printStackTrace(); } }