public Stack arguments() { Stack arguments = new Stack(); arguments.push(SleepUtils.getScalar(type)); arguments.push(SleepUtils.getScalar(pass)); arguments.push(SleepUtils.getScalar(user)); arguments.push(SleepUtils.getScalar(port)); arguments.push(SleepUtils.getScalar(host)); return arguments; }
public static void main(String[] args) { // sleepThread 不停的尝试睡眠 Thread sleepThread = new Thread(new SleepRunner(), "SleepThread"); sleepThread.setDaemon(true); // busyThread 不停的运行 Thread busyThread = new Thread(new BusyRunner(), "BusyThread"); busyThread.setDaemon(true); busyThread.start(); // 休息5秒,让sleepThread 和 busyThread 充分运行 SleepUtils.second(5); sleepThread.interrupt(); busyThread.interrupt(); System.out.println( "SleepThread interrupted is " + sleepThread.isInterrupted()); // false,InterruptException 会清除中断标识位 System.out.println("BusyThread interrupted is " + busyThread.isInterrupted()); // true // 防止sleepThread 和busyThread 立刻退出 SleepUtils.second(2); }
/** create an item every 2 seconds */ public void run() { while (!Thread.currentThread().isInterrupted()) { synchronized (items) { try { System.out.println(consumerName + " waiting ..."); waitForItemsAvailable(items); // Zugriff immer durch waitForItemsAvailable() sicher final Item item = items.remove(0); System.out.println(consumerName + " consuming " + item); SleepUtils.safeSleep(sleepTime); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }
public Scalar evaluate(ScriptEnvironment e) { Function callme = e.getFunction(function); Block inline = null; if (callme != null) { CallRequest.FunctionCallRequest request = new CallRequest.FunctionCallRequest(e, getLineNumber(), function, callme); request.CallFunction(); } else if ((inline = e.getBlock(function)) != null) { CallRequest.InlineCallRequest request = new CallRequest.InlineCallRequest(e, getLineNumber(), function, inline); request.CallFunction(); } else { e.getScriptInstance() .fireWarning("Attempted to call non-existent function " + function, getLineNumber()); e.FrameResult(SleepUtils.getEmptyScalar()); } return null; }
public void run() { while (true) { SleepUtils.second(10); // InterruptException 会清除中断标志位 } }