// --------------------------------actionDisconnect--------------------------- private void actionDisconnect() { try { oConn.disconnect(); tConn.join(2000); tMain.join(2000); } catch (Exception e) { } }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run MouseMoveThread " + x + ", " + y); while (!hasFocus()) { Thread.sleep(1000); } int x1 = lastMouseX; int x2 = x; int y1 = lastMouseY; int y2 = y; // shrink range by 1 px on both ends // manually move this 1px to trip DND code if (x1 != x2) { int dx = x - lastMouseX; if (dx > 0) { x1 += 1; x2 -= 1; } else { x1 -= 1; x2 += 1; } } if (y1 != y2) { int dy = y - lastMouseY; if (dy > 0) { y1 += 1; y2 -= 1; } else { y1 -= 1; y2 += 1; } } robot.setAutoDelay(Math.max(duration / 100, 1)); robot.mouseMove(x1, y1); int d = 100; for (int t = 0; t <= d; t++) { x1 = (int) easeInOutQuad( (double) t, (double) lastMouseX, (double) x2 - lastMouseX, (double) d); y1 = (int) easeInOutQuad( (double) t, (double) lastMouseY, (double) y2 - lastMouseY, (double) d); robot.mouseMove(x1, y1); } robot.mouseMove(x, y); lastMouseX = x; lastMouseY = y; robot.waitForIdle(); robot.setAutoDelay(1); } catch (Exception e) { log("Bad parameters passed to mouseMove"); e.printStackTrace(); } log("< run MouseMoveThread"); }
public void quit() { try { probeThread.join(5); } catch (InterruptedException e) { } probeThread = null; }
public synchronized void stop() { running = false; try { thread.join(); } catch (InterruptedException e) { thread.interrupt(); } }
// Fecha o jogo; M�todo join() espera a thread morrer. public synchronized void stop() { running = false; try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } }
public synchronized void stop() { if (!running) return; running = false; try { gameThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } }
public void stop() { quit = true; boolean hasQuit = false; while (!hasQuit) { try { thread.join(); hasQuit = true; } catch (InterruptedException e) { } } }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run MousePressThread"); while (!hasFocus()) { Thread.sleep(1000); } robot.mousePress(mask); robot.waitForIdle(); } catch (Exception e) { log("Bad parameters passed to mousePress"); e.printStackTrace(); } log("< run MousePressThread"); }
/** Iterate the physics, call repaint(). */ public void run() { while (true) { repaint(); try { canvas.changeSize(getHeight(), getWidth()); simthread.sleep(10); canvasthread.run(); canvasthread.join(); // this.iters++; } catch (Exception ie) { System.out.println(ie.getMessage() + "!!!"); } // System.out.println(iters + "!!"); } }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); // in different order so async works while (!hasFocus()) { Thread.sleep(1000); } Thread.sleep(delay); log("> run KeyPressThread"); _typeKey(charCode, keyCode, alt, ctrl, shift); } catch (Exception e) { log("Bad parameters passed to _typeKey"); e.printStackTrace(); } log("< run KeyPressThread"); }
public void testRequiredLayoutTriggeredWhilePerformingLayoutStillGetsRegistered() throws Exception { for (int i = 0; i < 100; i++) panel.add(new PropPanel(new MockProp())); panel.markAsNeedingLayout(); Thread thread = new Thread( new Runnable() { public void run() { panel.doLayout(); } }); thread.start(); while (panel.getChildren().get(0).needsLayout()) Thread.yield(); panel.markAsNeedingLayout(); thread.join(); assertEquals(true, panel.needsLayout()); }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run KeyDownThread"); while (!hasFocus()) { Thread.sleep(1000); } int vkCode = getVKCode(charCode, keyCode); if (charCode >= 32) { // if it is printable, then it lives in our hashmap KeyEvent event = (KeyEvent) charMap.get(new Integer(charCode)); // see if we need to press shift to generate this // character if (event.isShiftDown()) { robot.keyPress(KeyEvent.VK_SHIFT); shift = true; } if (event.isAltGraphDown()) { robot.keyPress(KeyEvent.VK_ALT_GRAPH); altgraph = true; } } else { if (vkCode == KeyEvent.VK_ALT) { alt = true; } else if (vkCode == KeyEvent.VK_CONTROL) { ctrl = true; } else if (vkCode == KeyEvent.VK_SHIFT) { shift = true; } else if (vkCode == KeyEvent.VK_ALT_GRAPH) { altgraph = true; } } if (!isUnsafe(vkCode)) { robot.keyPress(vkCode); } } catch (Exception e) { log("Bad parameters passed to downKey"); e.printStackTrace(); } log("< run KeyDownThread"); }
void killPlayThread() { tellThreadToStop(); try { if (playThread != null) { while (playThread.isAlive()) { try { playThread.interrupt(); } // Ignore security exceptions resulting from // attempting to interrupt a thread. // TODO Explain this better. catch (SecurityException ex) { } playThread.join(50); } playThread = null; } } catch (InterruptedException ex) { System.out.println("Interrupted while killing the play thread. Shouldn't happen."); } }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run MouseWheelThread " + amount); while (!hasFocus()) { Thread.sleep(1000); } int dir = 1; if (System.getProperty("os.name").toUpperCase().indexOf("MAC") != -1) { // yay for Apple dir = -1; } robot.setAutoDelay(Math.max(duration / Math.abs(amount), 1)); for (int i = 0; i < Math.abs(amount); i++) { robot.mouseWheel(amount > 0 ? dir : -dir); } robot.setAutoDelay(1); } catch (Exception e) { log("Bad parameters passed to mouseWheel"); e.printStackTrace(); } log("< run MouseWheelThread "); }
void joinAppletThread() throws InterruptedException { if (handler != null) { handler.join(); handler = null; } }
public static void main(String[] args) throws Exception { SwingUtilities.invokeAndWait( new Runnable() { public void run() { label = new JLabel("A JLabel used as object for an HTML-formatted tooltip"); label.setToolTipText( "<html><body bgcolor=FFFFE1>An HTML-formatted ToolTip</body></html>"); frame = new JFrame(); frame.add(label); frame.pack(); frame.setVisible(true); } }); ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { ToolTipManager toolTipManager = ToolTipManager.sharedInstance(); toolTipManager.setInitialDelay(0); toolTipManager.mouseMoved(new MouseEvent(label, 0, 0, 0, 0, 0, 0, false)); } }); Thread.sleep(500); SwingUtilities.invokeAndWait( new Runnable() { public void run() { toolTipWidth = getTipWindow().getWidth(); frame.dispose(); } }); Thread thread = new Thread( new ThreadGroup("Some ThreadGroup"), new Runnable() { public void run() { SunToolkit.createNewAppContext(); try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { frame = new JFrame(); frame.add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { ToolTipManager toolTipManager = ToolTipManager.sharedInstance(); toolTipManager.setInitialDelay(0); toolTipManager.mouseMoved(new MouseEvent(label, 0, 0, 0, 0, 0, 0, false)); } }); Thread.sleep(500); SwingUtilities.invokeAndWait( new Runnable() { public void run() { int newToolTipWidth = getTipWindow().getWidth(); frame.dispose(); if (toolTipWidth != newToolTipWidth) { throw new RuntimeException( "Tooltip width is different. Initial: " + toolTipWidth + ", new: " + newToolTipWidth); } } }); } catch (Exception e) { throw new RuntimeException(e); } } }); thread.start(); thread.join(); }
private void processResources(Session session, Element element, HashMap additionalInformation) { dataFiles = new ArrayList(); missingDataFiles = new ArrayList(); NodeList elements = element.getChildNodes(); process(session, elements, additionalInformation); if (missingDataFiles.size() > 0) { StringBuffer message = new StringBuffer(); message.append("<html>The following data file(s) could not be located.<ul>"); for (ResourceLocator file : missingDataFiles) { if (file.isLocal()) { message.append("<li>"); message.append(file.getPath()); message.append("</li>"); } else { message.append("<li>Server: "); message.append(file.getServerURL()); message.append(" Path: "); message.append(file.getPath()); message.append("</li>"); } } message.append("</ul>"); message.append("Common reasons for this include: "); message.append("<ul><li>The session or data files have been moved.</li> "); message.append( "<li>The data files are located on a drive that is not currently accessible.</li></ul>"); message.append("</html>"); MessageUtils.showMessage(message.toString()); } if (dataFiles.size() > 0) { final List<String> errors = new ArrayList<String>(); // Load files concurrently -- TODO, put a limit on # of threads? List<Thread> threads = new ArrayList(dataFiles.size()); long t0 = System.currentTimeMillis(); int i = 0; List<Runnable> synchronousLoads = new ArrayList<Runnable>(); for (final ResourceLocator locator : dataFiles) { final String suppliedPath = locator.getPath(); final String relPath = fullToRelPathMap.get(suppliedPath); Runnable runnable = new Runnable() { public void run() { List<Track> tracks = null; try { tracks = igv.load(locator); for (Track track : tracks) { if (track == null) { log.info("Null track for resource " + locator.getPath()); continue; } String id = track.getId(); if (id == null) { log.info("Null track id for resource " + locator.getPath()); continue; } if (relPath != null) { id = id.replace(suppliedPath, relPath); } List<Track> trackList = trackDictionary.get(id); if (trackList == null) { trackList = new ArrayList(); trackDictionary.put(id, trackList); } trackList.add(track); } } catch (Exception e) { log.error("Error loading resource " + locator.getPath(), e); String ms = "<b>" + locator.getPath() + "</b><br>&nbs;p " + e.toString() + "<br>"; errors.add(ms); } } }; boolean isAlignment = locator.getPath().endsWith(".bam") || locator.getPath().endsWith(".entries") || locator.getPath().endsWith(".sam"); // Run synchronously if in batch mode or if there are no "track" elments, or if this is an // alignment file if (isAlignment || Globals.isBatch() || !hasTrackElments) { synchronousLoads.add(runnable); } else { Thread t = new Thread(runnable); threads.add(t); t.start(); } i++; } // Wait for all threads to complete for (Thread t : threads) { try { t.join(); } catch (InterruptedException ignore) { } } // Now load data that must be loaded synchronously for (Runnable runnable : synchronousLoads) { runnable.run(); } long dt = System.currentTimeMillis() - t0; log.debug("Total load time = " + dt); if (errors.size() > 0) { StringBuffer buf = new StringBuffer(); buf.append("<html>Errors were encountered loading the session:<br>"); for (String msg : errors) { buf.append(msg); } MessageUtils.showMessage(buf.toString()); } } dataFiles = null; }
public AeronLatencyUnderLoadPublisher(final String[] args) { try { parseArgs(args); } catch (final ParseException e) { throw new RuntimeException(e); } final Aeron.Context ctx = new Aeron.Context().newImageHandler(this::imageHandler); fragmentHandler = new FragmentAssembler(this::msgHandler); final Aeron aeron = Aeron.connect(ctx); System.out.println("Reflect: " + reflectChannel + " Pub: " + pubChannel); pub = aeron.addPublication(pubChannel, pubStreamId); sub = aeron.addSubscription(reflectChannel, subStreamId); imageLatch = new CountDownLatch(1); final IdleStrategy idle = new BusySpinIdleStrategy(); bufferClaim = new BufferClaim(); final List<RateControllerInterval> intervals = new ArrayList<>(); intervals.add(new MessagesAtMessagesPerSecondInterval(100, 10)); intervals.add(new MessagesAtMessagesPerSecondInterval(1000, 100)); intervals.add(new MessagesAtMessagesPerSecondInterval(10000, 1000)); intervals.add(new MessagesAtMessagesPerSecondInterval(100000, 10000)); intervals.add(new MessagesAtMessagesPerSecondInterval(1000000, 100000)); intervals.add(new MessagesAtMessagesPerSecondInterval(10000000, 1000000)); intervals.add(new MessagesAtMessagesPerSecondInterval(30000000, 3000000)); buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(msgLen)); msgCount = 0; RateController rateController = null; try { rateController = new RateController(this, intervals); } catch (final Exception ex) { throw new RuntimeException(ex); } final Runnable task = () -> { while (running) { while (sub.poll(fragmentHandler, 1) <= 0 && running) {} } System.out.println("Done"); }; final Thread subThread = new Thread(task); subThread.start(); try { imageLatch.await(); } catch (final InterruptedException e) { e.printStackTrace(); } final int warmUpMsgs = 100000; for (int i = 0; i < warmUpMsgs; i++) { while (pub.tryClaim(buffer.capacity(), bufferClaim) < 0L) { idle.idle(1); } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); buffer.putByte(offset, (byte) 'w'); bufferClaim.commit(); } try { Thread.sleep(1000); } catch (final InterruptedException e) { e.printStackTrace(); } System.out.println("warmup msgs received: " + warmups); final int start = (int) System.currentTimeMillis(); while (rateController.next()) {} final int total = (int) (System.currentTimeMillis() - start) / 1000; buffer.putByte(0, (byte) 'q'); while (pub.offer(buffer, 0, buffer.capacity()) < 0L) { idle.idle(0); } System.out.println("Duration: " + total + " seconds"); try { Thread.sleep(1000); } catch (final InterruptedException e) { e.printStackTrace(); } running = false; try { subThread.join(); } catch (final InterruptedException e) { e.printStackTrace(); } aeron.close(); try { computeStats(); } catch (IOException e) { e.printStackTrace(); } }
/** * Execute applet events. Here is the state transition diagram * * <pre>{@literal * Note: (XXX) is the action * APPLET_XXX is the state * (applet code loaded) --> APPLET_LOAD -- (applet init called)--> APPLET_INIT -- * (applet start called) --> APPLET_START -- (applet stop called) --> APPLET_STOP -- * (applet destroyed called) --> APPLET_DESTROY --> (applet gets disposed) --> * APPLET_DISPOSE --> ... * }</pre> * * In the legacy lifecycle model. The applet gets loaded, inited and started. So it stays in the * APPLET_START state unless the applet goes away(refresh page or leave the page). So the applet * stop method called and the applet enters APPLET_STOP state. Then if the applet is revisited, it * will call applet start method and enter the APPLET_START state and stay there. * * <p>In the modern lifecycle model. When the applet first time visited, it is same as legacy * lifecycle model. However, when the applet page goes away. It calls applet stop method and * enters APPLET_STOP state and then applet destroyed method gets called and enters APPLET_DESTROY * state. * * <p>This code is also called by AppletViewer. In AppletViewer "Restart" menu, the applet is jump * from APPLET_STOP to APPLET_DESTROY and to APPLET_INIT . * * <p>Also, the applet can jump from APPLET_INIT state to APPLET_DESTROY (in Netscape/Mozilla * case). Same as APPLET_LOAD to APPLET_DISPOSE since all of this are triggered by browser. */ @Override public void run() { Thread curThread = Thread.currentThread(); if (curThread == loaderThread) { // if we are in the loader thread, cause // loading to occur. We may exit this with // status being APPLET_DISPOSE, APPLET_ERROR, // or APPLET_LOAD runLoader(); return; } boolean disposed = false; while (!disposed && !curThread.isInterrupted()) { AppletEvent evt; try { evt = getNextEvent(); } catch (InterruptedException e) { showAppletStatus("bail"); return; } // showAppletStatus("EVENT = " + evt.getID()); try { switch (evt.getID()) { case APPLET_LOAD: if (!okToLoad()) { break; } // This complexity allows loading of applets to be // interruptable. The actual thread loading runs // in a separate thread, so it can be interrupted // without harming the applet thread. // So that we don't have to worry about // concurrency issues, the main applet thread waits // until the loader thread terminates. // (one way or another). if (loaderThread == null) { setLoaderThread(new Thread(null, this, "AppletLoader", 0, false)); loaderThread.start(); // we get to go to sleep while this runs loaderThread.join(); setLoaderThread(null); } else { // REMIND: issue an error -- this case should never // occur. } break; case APPLET_INIT: // AppletViewer "Restart" will jump from destroy method to // init, that is why we need to check status w/ APPLET_DESTROY if (status != APPLET_LOAD && status != APPLET_DESTROY) { showAppletStatus("notloaded"); break; } applet.resize(defaultAppletSize); if (PerformanceLogger.loggingEnabled()) { PerformanceLogger.setTime("Applet Init"); PerformanceLogger.outputLog(); } applet.init(); // Need the default(fallback) font to be created in this AppContext Font f = getFont(); if (f == null || "dialog".equals(f.getFamily().toLowerCase(Locale.ENGLISH)) && f.getSize() == 12 && f.getStyle() == Font.PLAIN) { setFont(new Font(Font.DIALOG, Font.PLAIN, 12)); } // Validate the applet in event dispatch thread // to avoid deadlock. try { final AppletPanel p = this; Runnable r = new Runnable() { @Override public void run() { p.validate(); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } status = APPLET_INIT; showAppletStatus("inited"); break; case APPLET_START: { if (status != APPLET_INIT && status != APPLET_STOP) { showAppletStatus("notinited"); break; } applet.resize(currentAppletSize); applet.start(); // Validate and show the applet in event dispatch thread // to avoid deadlock. try { final AppletPanel p = this; final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { p.validate(); a.setVisible(true); // Fix for BugTraq ID 4041703. // Set the default focus for an applet. if (hasInitialFocus()) { setDefaultFocus(); } } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } status = APPLET_START; showAppletStatus("started"); break; } case APPLET_STOP: if (status != APPLET_START) { showAppletStatus("notstarted"); break; } status = APPLET_STOP; // Hide the applet in event dispatch thread // to avoid deadlock. try { final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { a.setVisible(false); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } // During Applet.stop(), any AccessControlException on an involved Class remains in // the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is // reused, the same exception will occur during class loading. Set the // AppletClassLoader's // exceptionStatusSet flag to allow recognition of what had happened // when reusing AppletClassLoader object. try { applet.stop(); } catch (java.security.AccessControlException e) { setExceptionStatus(e); // rethrow exception to be handled as it normally would be. throw e; } showAppletStatus("stopped"); break; case APPLET_DESTROY: if (status != APPLET_STOP && status != APPLET_INIT) { showAppletStatus("notstopped"); break; } status = APPLET_DESTROY; // During Applet.destroy(), any AccessControlException on an involved Class remains in // the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is // reused, the same exception will occur during class loading. Set the // AppletClassLoader's // exceptionStatusSet flag to allow recognition of what had happened // when reusing AppletClassLoader object. try { applet.destroy(); } catch (java.security.AccessControlException e) { setExceptionStatus(e); // rethrow exception to be handled as it normally would be. throw e; } showAppletStatus("destroyed"); break; case APPLET_DISPOSE: if (status != APPLET_DESTROY && status != APPLET_LOAD) { showAppletStatus("notdestroyed"); break; } status = APPLET_DISPOSE; try { final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { remove(a); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } applet = null; showAppletStatus("disposed"); disposed = true; break; case APPLET_QUIT: return; } } catch (Exception e) { status = APPLET_ERROR; if (e.getMessage() != null) { showAppletStatus("exception2", e.getClass().getName(), e.getMessage()); } else { showAppletStatus("exception", e.getClass().getName()); } showAppletException(e); } catch (ThreadDeath e) { showAppletStatus("death"); return; } catch (Error e) { status = APPLET_ERROR; if (e.getMessage() != null) { showAppletStatus("error2", e.getClass().getName(), e.getMessage()); } else { showAppletStatus("error", e.getClass().getName()); } showAppletException(e); } clearLoadAbortRequest(); } }