?? winner.java
字號:
package push;import feedback.Feedback;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;/** * Selects winner * * @version 1.0 * @since 1.0 * @see Runnable */public final class Winner implements Runnable { private final PushInitiator pusher; private final String winnerUrl; private final String addressType; /** * Creates a new <code>Winner</code> instance. * * @param pusher * a <code>PushInitiator</code> value * @param winnerUrl * a <code>String</code> value */ public Winner(PushInitiator pusher, String winnerUrl, String addressType) { this.pusher = pusher; this.winnerUrl = winnerUrl; this.addressType = addressType; } /** * A checker thread selects a winner from the users that has returned * feedback. A winner (if any) is selected during every cycle (of the while * loop). */ public void run() { String message = PushInitiator.createSiMessage(winnerUrl, null, null, null, null, "You are lucky! Check the message"); while (true) { try { Vector users = User.getUsersOnline(); for (int i = 0; i < users.size(); i++) { User user = (User) users.get(i); String name = user.getName(); if (Feedback.winner().equals(name)) { String address = user.getAddress(addressType); if (address != null && !address.trim().equals("")) { try { pusher.sendPushMessage(address, addressType, message, PushService.SI_CONTENT_TYPE); } catch (Exception ee) { } } } } } catch (Exception e) { System.err.println(e); } try { Thread.sleep(120000); // 2 min } catch (InterruptedException e) { } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -