wait

Thread.sleep() implementation

霸气de小男生 提交于 2019-12-03 02:20:43
问题 Today I had an interview on which I asked candidate quite usual and basic question about the difference between Thread.sleep() and Object.wait() . I expected him to answer something like like this, but he said these methods basically are the same thing, and most likely Thread.sleep is using Object.wait() inside it, but sleep itself doesn't require external lock. This is not exactly a correct answer, because in JDK 1.6 this method have following signature. public static native void sleep(long

Runtime.exec().waitFor() doesn't wait until process is done

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have this code: File file = new File ( path + "\\RunFromCode.bat" ); file . createNewFile (); PrintWriter writer = new PrintWriter ( file , "UTF-8" ); for ( int i = 0 ; i <= MAX ; i ++) { writer . println ( "@cd " + i ); writer . println ( NATIVE SYSTEM COMMANDS ); // more things } writer . close (); Process p = Runtime . getRuntime (). exec ( "cmd /c start " + path + "\\RunFromCode.bat" ); p . waitFor (); file . delete (); What happens is that the file deleted before it actually executed. Is this because the .bat file contains

Temporarily bypassing implicit waits with WebDriver

倾然丶 夕夏残阳落幕 提交于 2019-12-03 01:24:26
When using implicit waits, as advised here , I still sometimes want to assert the immediate invisibility or non-existence of elements. In other words, I know some elements should be hidden, and want my tests make that assertion fast , without spending several seconds because of the (otherwise useful) implicit wait. One thing I tried was a helper method like this: // NB: doesn't seem to do what I want private boolean isElementHiddenNow(String id) { WebDriverWait zeroWait = new WebDriverWait(driver, 0); ExpectedCondition<Boolean> c = invisibilityOfElementLocated(By.id(id)); try { zeroWait.until

selenium元素和浏览器操作

匿名 (未验证) 提交于 2019-12-03 00:08:02
click和clear from selenium . webdriver . support . wait import WebDriverWait import time browser = webdriver . Chrome () browser . get ( 'https://www.baidu.cn/' ) wait = WebDriverWait ( browser , 10 ) input_tag = wait . until ( EC . presence_of_element_located (( By . ID , 'twotabsearchtextbox' ))) input_tag . send_keys ( 'iphone 8' ) button = browser . find_element_by_css_selector ( '#nav-search > form > div.nav-right > div > input' ) button . click () time . sleep ( 3 ) input_tag = browser . find_element_by_id ( 'twotabsearchtextbox' ) input_tag . clear () # 清空输入框 input_tag . send_keys (

永远都要把wait()放到循环语句里面!

匿名 (未验证) 提交于 2019-12-02 23:26:52
今天在网上看到一段代码,是模拟银行转账的,如何保证多次转账并发执行的时候,转出账户和转入账户的金额一致。 代码可谓巧妙绝伦!先看代码: public class MyLock { public static void main(String[] args) { // 模拟转出和转入账户 Account src = new Account(100000); Account target = new Account(100000); // 设置倒计时 CountDownLatch countDownLatch = new CountDownLatch(99999); for (int i = 0; i < 99999; i++) { Thread t1 = new Thread(() -> { // 每次转1元钱,共转9999次 src.transactionToTarget(1, target); countDownLatch.countDown(); }); t1.setName("Thread: " + i); t1.start(); } try { // 等待所有线程执行完毕 countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } // 打印账户余额 System.out

Wait for 5 seconds

孤人 提交于 2019-12-02 19:29:15
I want to wait 5 seconds before starting another public void method. The thread sleep was not working for me. If there is a way of wait() without using Threads I would love to know that. public void check(){ //activity of changing background color of relative layout } I want to wait 3 seconds before changing the relative layout color. just add one-liner with lambda (new Handler()).postDelayed(this::yourMethod, 5000); See if this works for you. Be sure to import the android.os.Handler Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { // yourMethod(); } },

Using wait in AsyncTask

风格不统一 提交于 2019-12-02 17:52:14
When using a wait in an AsyncTask , I get ERROR/AndroidRuntime(24230): Caused by: java.lang.IllegalMonitorStateException: object not locked by thread before wait() Is it possible to use an Asynctask just for waiting? How? Thanks class WaitSplash extends AsyncTask<Void, Void, Void> { protected Void doInBackground(Void... params) { try { wait(MIN_SPLASH_DURATION); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } protected void onPostExecute() { waitSplashFinished = true; finished(); } } Flo Use Thread.sleep() instead of wait() . You can