List of usage examples for java.lang Runnable run
public abstract void run();
Runnable
is used to create a thread, starting the thread causes the object's run
method to be called in that separately executing thread. From source file:nu.yona.server.device.service.DeviceService.java
private void setAppLastOpenedDateIfNewer(LocalDate now, Supplier<Optional<LocalDate>> currentDateSupplier, Runnable dateSetter) { Optional<LocalDate> appLastOpenedDate = currentDateSupplier.get(); if (!appLastOpenedDate.isPresent() || appLastOpenedDate.get().isBefore(now)) { dateSetter.run(); }/*w w w.j a v a 2 s . c om*/ }
From source file:com.ponysdk.ui.server.basic.PPusher.java
public boolean execute(final Runnable runnable) { try {/*from w ww .ja v a 2s .c om*/ if (UIContext.get() == null) { begin(); try { final Txn txn = Txn.get(); txn.begin(txnContext); try { runnable.run(); txn.commit(); } catch (final Throwable e) { log.error("Cannot process commmand", e); txn.rollback(); return false; } } finally { end(); } } else { runnable.run(); } } catch (final Throwable e) { log.error("Cannot execute command : " + runnable, e); return false; } return true; }
From source file:kihira.tails.client.gui.GuiExport.java
@Override protected void actionPerformed(GuiButton button) { //Export to file if (button.id == 0 || button.id == 1 || button.id == 2) { AbstractClientPlayer player = this.mc.thePlayer; File file;/*from w w w . j a v a 2 s . c o m*/ this.exportMessage = ""; this.exportLoc = null; if (button.id == 0) file = new File(System.getProperty("user.home")); else if (button.id == 1) file = new File(System.getProperty("user.dir")); else { JFileChooser fileChooser = new JFileChooser(new File(System.getProperty("user.dir"))); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.showSaveDialog(Display.getParent()) == JFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); } else return; } if (file.exists() && file.canWrite()) { this.exportLoc = file.toURI(); file = new File(file, File.separatorChar + player.getCommandSenderName() + ".png"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to create skin file! %s", e)); e.printStackTrace(); } } BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, player); if (image != null) { try { ImageIO.write(image, "png", file); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to save skin file! %s", e)); e.printStackTrace(); } } else { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to export skin, image was null!")); file.delete(); } } if (Strings.isNullOrEmpty(this.exportMessage)) { savePartsData(); this.openFolderButton.visible = true; setExportMessage(EnumChatFormatting.GREEN + I18n.format("tails.export.success", file)); } } if (button.id == 3 && this.exportLoc != null) { try { Desktop.getDesktop().browse(this.exportLoc); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to open export location: %s", e)); e.printStackTrace(); } } //Upload if (button.id == 10) { final BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, this.mc.thePlayer); Runnable runnable = new Runnable() { @Override public void run() { exportMessage = I18n.format("tails.uploading"); new ImgurUpload().uploadImage(image); } }; runnable.run(); } }
From source file:acmi.l2.clientmod.xdat.XdatEditor.java
public void execute(Callable<Void> r, Consumer<Exception> exceptionConsumer, Runnable finallyCallback) { executor.execute(() -> {/*w ww. ja v a 2 s. c om*/ Platform.runLater(() -> working.set(true)); try { r.call(); } catch (Exception e) { if (exceptionConsumer != null) exceptionConsumer.accept(e); } finally { try { if (finallyCallback != null) finallyCallback.run(); } finally { Platform.runLater(() -> working.set(false)); } } }); }
From source file:de.jaetzold.philips.hue.HueLightBulb.java
@Override public void stateChangeTransaction(Integer transitionTime, Runnable changes) { openStateChangeTransaction(transitionTime); try {/* www .j a v a 2 s. c o m*/ try { changes.run(); } catch (Throwable t) { stateTransactionJson.set(null); //noinspection ThrowCaughtLocally throw t; } finally { commitStateChangeTransaction(); } } catch (Throwable t) { // do kind of rollback by syncing the state from the bridge sync(); } }
From source file:Main.java
public static void animateTextChange(final TextView view, @IdRes final int toText, final Runnable rWhenEnd) { ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f); final ObjectAnimator restore = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f); alpha.setDuration(DURATION_SHORT);/*from w w w.j a v a 2 s. c om*/ alpha.setInterpolator(new AccelerateDecelerateInterpolator()); restore.setDuration(DURATION_SHORT); restore.setInterpolator(new AccelerateDecelerateInterpolator()); alpha.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { // Do nothing. } @SuppressWarnings("ResourceType") @Override public void onAnimationEnd(Animator animation) { view.setText(toText); restore.start(); } @SuppressWarnings("ResourceType") @Override public void onAnimationCancel(Animator animation) { view.setText(toText); } @Override public void onAnimationRepeat(Animator animation) { // Do nothing. } }); if (rWhenEnd != null) restore.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { rWhenEnd.run(); } @Override public void onAnimationCancel(Animator animation) { rWhenEnd.run(); } @Override public void onAnimationRepeat(Animator animation) { } }); alpha.start(); }
From source file:de.micromata.genome.chronos.spi.ram.RamJobStore.java
@Override public void withinTransaction(final Runnable runnable) { runnable.run(); // NOSONAR false positive }
From source file:io.hummer.util.ws.AbstractNode.java
@WebMethod @SOAPBinding(parameterStyle = ParameterStyle.BARE, style = Style.DOCUMENT, use = Use.LITERAL) public void terminate(@WebParam final TerminateRequest params) { new Thread() { public void run() { logger.info("Node " + this + " is terminating..."); // actually, the Runtime Shutdown Hook should also cause the terminate task to be executed // when the Java process dies, but let's do the job here too, since we assume that doing // it twice is better than not doing it at all.. try { Runnable r = getTerminateTask(params); if (r != null) r.run(); } catch (Exception e) { }//from w ww . ja va 2 s . c o m try { Thread.sleep(2500); } catch (InterruptedException e) { } System.exit(0); } }.start(); return; }
From source file:io.druid.server.namespace.cache.NamespaceExtractionCacheManagerExecutorsTest.java
@Test(timeout = 50_000) public void testShutdown() throws NoSuchFieldException, IllegalAccessException, InterruptedException, ExecutionException { final CountDownLatch latch = new CountDownLatch(1); final ListenableFuture future; final AtomicLong runs = new AtomicLong(0); long prior = 0; try {/*from ww w . j a v a2 s .c o m*/ final URIExtractionNamespace namespace = new URIExtractionNamespace("ns", tmpFile.toURI(), new URIExtractionNamespace.ObjectMapperFlatDataParser( URIExtractionNamespaceTest.registerTypes(new ObjectMapper())), new Period(1l), null); final String cacheId = UUID.randomUUID().toString(); final Runnable runnable = manager.getPostRunnable(namespace, factory, cacheId); future = manager.schedule(namespace, factory, new Runnable() { @Override public void run() { runnable.run(); latch.countDown(); runs.incrementAndGet(); } }, cacheId); latch.await(); Assert.assertFalse(future.isCancelled()); Assert.assertFalse(future.isDone()); prior = runs.get(); while (runs.get() <= prior) { Thread.sleep(50); } Assert.assertTrue(runs.get() > prior); } finally { lifecycle.stop(); } manager.waitForServiceToEnd(1_000, TimeUnit.MILLISECONDS); prior = runs.get(); Thread.sleep(50); Assert.assertEquals(prior, runs.get()); Field execField = NamespaceExtractionCacheManager.class .getDeclaredField("listeningScheduledExecutorService"); execField.setAccessible(true); Assert.assertTrue(((ListeningScheduledExecutorService) execField.get(manager)).isShutdown()); Assert.assertTrue(((ListeningScheduledExecutorService) execField.get(manager)).isTerminated()); }
From source file:com.tapfortap.phonegap.TapForTapPhoneGapPlugin.java
private void getRootLayout(final Runnable r) { (cordova.getActivity()).runOnUiThread(new Runnable() { @Override/*from ww w. j a va 2 s. co m*/ public void run() { if (rootLayout == null) { ViewGroup viewGroup = (ViewGroup) (cordova.getActivity()).findViewById(android.R.id.content); rootLayout = (LinearLayout) viewGroup.getChildAt(0); } if (r != null) r.run(); } }); }